Skip to content

Commit 0aace78

Browse files
committed
feat: enhance list command output with table formatting
1 parent 653bf5c commit 0aace78

File tree

3 files changed

+57
-14
lines changed

3 files changed

+57
-14
lines changed

cmd/list.go

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,30 @@ package cmd
22

33
import (
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+
1218
var 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+
1929
func 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
}

go.mod

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.23.3
44

55
require (
66
github.com/fatih/color v1.16.0
7+
github.com/olekukonko/tablewriter v1.1.0
78
github.com/spf13/cobra v1.8.0
89
gopkg.in/yaml.v3 v3.0.1
910
)
@@ -12,6 +13,10 @@ require (
1213
github.com/inconshreveable/mousetrap v1.1.0 // indirect
1314
github.com/mattn/go-colorable v0.1.13 // indirect
1415
github.com/mattn/go-isatty v0.0.20 // indirect
16+
github.com/mattn/go-runewidth v0.0.16 // indirect
17+
github.com/olekukonko/errors v1.1.0 // indirect
18+
github.com/olekukonko/ll v0.0.9 // indirect
19+
github.com/rivo/uniseg v0.4.7 // indirect
1520
github.com/spf13/pflag v1.0.5 // indirect
16-
golang.org/x/sys v0.14.0 // indirect
21+
golang.org/x/sys v0.30.0 // indirect
1722
)

go.sum

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,26 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
88
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
99
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
1010
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
11+
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
12+
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
13+
github.com/olekukonko/errors v1.1.0 h1:RNuGIh15QdDenh+hNvKrJkmxxjV4hcS50Db478Ou5sM=
14+
github.com/olekukonko/errors v1.1.0/go.mod h1:ppzxA5jBKcO1vIpCXQ9ZqgDh8iwODz6OXIGKU8r5m4Y=
15+
github.com/olekukonko/ll v0.0.9 h1:Y+1YqDfVkqMWuEQMclsF9HUR5+a82+dxJuL1HHSRpxI=
16+
github.com/olekukonko/ll v0.0.9/go.mod h1:En+sEW0JNETl26+K8eZ6/W4UQ7CYSrrgg/EdIYT2H8g=
17+
github.com/olekukonko/tablewriter v1.1.0 h1:N0LHrshF4T39KvI96fn6GT8HEjXRXYNDrDjKFDB7RIY=
18+
github.com/olekukonko/tablewriter v1.1.0/go.mod h1:5c+EBPeSqvXnLLgkm9isDdzR3wjfBkHR9Nhfp3NWrzo=
19+
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
20+
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
21+
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
1122
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
1223
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
1324
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
1425
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
1526
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
1627
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1728
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
18-
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
19-
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
29+
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
30+
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
2031
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2132
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2233
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

0 commit comments

Comments
 (0)