@@ -2,20 +2,30 @@ package cmd
22
33import (
44 "fmt"
5+ "os"
56 "strings"
67
78 "github.com/fatih/color"
89 "github.com/gambitier/tag-manager/pkg/discovery"
10+ "github.com/olekukonko/tablewriter"
911 "github.com/spf13/cobra"
1012)
1113
14+ var (
15+ verbose bool
16+ )
17+
1218var listCmd = & cobra.Command {
1319 Use : "list" ,
1420 Short : "List discovered Go packages" ,
1521 Long : `List all discovered Go packages across multiple repositories with their configuration status.` ,
1622 RunE : runList ,
1723}
1824
25+ func init () {
26+ listCmd .Flags ().BoolVarP (& verbose , "verbose" , "v" , false , "Show detailed information (module path, go version, github repo)" )
27+ }
28+
1929func runList (cmd * cobra.Command , args []string ) error {
2030 // Discover packages
2131 searchPaths := discovery .GetDefaultSearchPaths ()
@@ -34,23 +44,40 @@ func runList(cmd *cobra.Command, args []string) error {
3444 color .White ("Search paths: %s" , strings .Join (searchPaths , ", " ))
3545 color .White ("" )
3646
47+ // Create table with modern API
48+ table := tablewriter .NewWriter (os .Stdout )
49+
50+ if verbose {
51+ table .Header ("#" , "Module" , "Package" , "Go Version" , "GitHub" , "Latest Tag" )
52+ } else {
53+ table .Header ("#" , "Package" , "Latest Tag" )
54+ }
55+
56+ // Add rows
3757 for i , pkg := range packages {
38- color .White ("%d. %s" , i + 1 , pkg .ModulePath )
39- fmt .Printf (" Path: %s\n " , pkg .Path )
40- fmt .Printf (" Package: %s\n " , pkg .PackageName )
41- if pkg .GoVersion != "" {
42- fmt .Printf (" Go Version: %s\n " , pkg .GoVersion )
58+ // Handle empty values
59+ goVersion := pkg .GoVersion
60+ if goVersion == "" {
61+ goVersion = "-"
4362 }
44- if pkg .GitHubRepo != "" {
45- fmt .Printf (" GitHub: %s\n " , pkg .GitHubRepo )
63+
64+ github := pkg .GitHubRepo
65+ if github == "" {
66+ github = "-"
4667 }
47- if pkg .LatestTag != "" {
48- fmt .Printf (" Latest Tag: %s\n " , pkg .LatestTag )
68+
69+ latestTag := pkg .LatestTag
70+ if latestTag == "" {
71+ latestTag = "(no tags)"
72+ }
73+
74+ if verbose {
75+ table .Append (fmt .Sprintf ("%d" , i + 1 ), pkg .ModulePath , pkg .PackageName , goVersion , github , latestTag )
4976 } else {
50- fmt .Printf ( " Latest Tag: (no tags found) \n " )
77+ table . Append ( fmt .Sprintf ( "%d" , i + 1 ), pkg . PackageName , latestTag )
5178 }
52- color .White ("" )
5379 }
5480
81+ table .Render ()
5582 return nil
5683}
0 commit comments