Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for recursive dep graph #137

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions estimate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"sort"
"strings"

"github.com/logrusorgru/aurora"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this library is not packaged in debian too. it's not so important to have colorful output...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: golang-github-logrusorgru-aurora-dev
entered Debian on 2020-07-10

"github.com/ramantehlan/GoCheckDeb/pkg/gocheckdeb"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we need to get github.com/ramantehlan/GoCheckDeb packaged for Debian first. 🤔

"golang.org/x/tools/go/vcs"
"golang.org/x/tools/refactor/importgraph"
)
Expand Down Expand Up @@ -173,8 +175,44 @@ func estimate(importpath string) error {
return nil
}

func recursiveEstimate(importpath string, formatType string) error {
log.Print(aurora.Bold(aurora.Green("[DebGoGraph Starting]")))

debFilter := true
displayAll := true

fmt.Printf("\nGolang package: %s\n", aurora.Bold(importpath))
fmt.Printf("Output type: %s\n", aurora.Bold(formatType))
fmt.Printf("Deb filter: %v\n", aurora.Bold(debFilter))
fmt.Printf("Display all deb (false for only main package): %v\n\n", aurora.Bold(displayAll))

fmt.Printf("Fetching dependencies of %s | It may take a while.\n\n", aurora.Bold(aurora.BrightBlue(importpath)))

// List | Graph | Tree
m, err := gocheckdeb.GetDep(importpath, "imports", formatType)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of using many third-party libraries. Especially this library has some overlap functions with dh-make-golang.

if err != nil {
fmt.Println(err)
}
m2, err := gocheckdeb.GetDep(importpath, "test", formatType)
if err != nil {
fmt.Println(err)
}
// DepMaps | DebFilder - display deb unpacked | displayAll - Display all unpacked or just head | inc start
fmt.Println(aurora.Bold(aurora.BrightBlue("--Project Dependencies--")))
gocheckdeb.PrintDep(m, debFilter, displayAll, 0)
fmt.Println(aurora.Bold(aurora.BrightBlue("--Test Dependencies--")))
gocheckdeb.PrintDep(m2, debFilter, displayAll, 0)

fmt.Println("")
log.Print(aurora.Bold(aurora.Green("[DebGoGraph Ending]")))

return nil
}

func execEstimate(args []string) {
fs := flag.NewFlagSet("estimate", flag.ExitOnError)
recursiveFlag := fs.Bool("r", false, "(Bool) Recursive output")
formatFlag := fs.String("format", "graph", "('graph', 'map', 'list') Format for the flag")

fs.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s estimate <go-package-importpath>\n", os.Args[0])
Expand All @@ -188,14 +226,18 @@ func execEstimate(args []string) {
log.Fatal(err)
}

if fs.NArg() != 1 {
if fs.NArg() < 1 {
fs.Usage()
os.Exit(1)
}

// TODO: support the -git_revision flag

if err := estimate(fs.Arg(0)); err != nil {
if *recursiveFlag {
err := recursiveEstimate(fs.Arg(0), *formatFlag)
if err != nil {
log.Fatal(err)
}
} else if err := estimate(fs.Arg(0)); err != nil {
log.Fatal(err)
}
}