diff --git a/estimate.go b/estimate.go index 5d10cf5..168f495 100644 --- a/estimate.go +++ b/estimate.go @@ -12,6 +12,8 @@ import ( "sort" "strings" + "github.com/logrusorgru/aurora" + "github.com/ramantehlan/GoCheckDeb/pkg/gocheckdeb" "golang.org/x/tools/go/vcs" "golang.org/x/tools/refactor/importgraph" ) @@ -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) + 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 \n", os.Args[0]) @@ -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) } }