summaryrefslogtreecommitdiffstats
path: root/cmd/deploy/list.go
diff options
context:
space:
mode:
authorbndw <ben@bdw.to>2026-01-23 21:52:50 -0800
committerbndw <ben@bdw.to>2026-01-23 21:52:50 -0800
commit87752492d0dc7df3cf78011d5ce315a3eb0cad51 (patch)
tree76843c127fece33f5c28dd7bd533044043478825 /cmd/deploy/list.go
parent57eb67df265a7a6bb544cde83a3be5eadf53fdf2 (diff)
Restructure CLI with Cobra
Replace custom switch-based routing with Cobra for cleaner command hierarchy. Reorganize commands into logical groups: - Root command handles deployment (--binary, --static, --domain, etc.) - App management at top level: list, logs, status, restart, remove - env subcommand group: list, set, unset - host subcommand group: init, status, update, ssh - Standalone: ui (renamed from webui), version Add version command with ldflags support for build info.
Diffstat (limited to 'cmd/deploy/list.go')
-rw-r--r--cmd/deploy/list.go36
1 files changed, 17 insertions, 19 deletions
diff --git a/cmd/deploy/list.go b/cmd/deploy/list.go
index ce1605b..ab19a12 100644
--- a/cmd/deploy/list.go
+++ b/cmd/deploy/list.go
@@ -1,44 +1,41 @@
1package main 1package main
2 2
3import ( 3import (
4 "flag"
5 "fmt" 4 "fmt"
6 "os" 5 "os"
7 "text/tabwriter" 6 "text/tabwriter"
8 7
9 "github.com/bdw/deploy/internal/state" 8 "github.com/bdw/deploy/internal/state"
9 "github.com/spf13/cobra"
10) 10)
11 11
12func runList(args []string) { 12var listCmd = &cobra.Command{
13 fs := flag.NewFlagSet("list", flag.ExitOnError) 13 Use: "list",
14 host := fs.String("host", "", "VPS host (SSH config alias or user@host)") 14 Short: "List all deployed apps and sites",
15 fs.Parse(args) 15 RunE: runList,
16}
16 17
17 // Load state 18func runList(cmd *cobra.Command, args []string) error {
18 st, err := state.Load() 19 st, err := state.Load()
19 if err != nil { 20 if err != nil {
20 fmt.Fprintf(os.Stderr, "Error loading state: %v\n", err) 21 return fmt.Errorf("error loading state: %w", err)
21 os.Exit(1)
22 } 22 }
23 23
24 // Get host from flag or state default 24 host := hostFlag
25 if *host == "" { 25 if host == "" {
26 *host = st.GetDefaultHost() 26 host = st.GetDefaultHost()
27 } 27 }
28 28
29 if *host == "" { 29 if host == "" {
30 fmt.Fprintf(os.Stderr, "Error: --host is required\n") 30 return fmt.Errorf("--host is required")
31 fs.Usage()
32 os.Exit(1)
33 } 31 }
34 32
35 apps := st.ListApps(*host) 33 apps := st.ListApps(host)
36 if len(apps) == 0 { 34 if len(apps) == 0 {
37 fmt.Printf("No deployments found for %s\n", *host) 35 fmt.Printf("No deployments found for %s\n", host)
38 return 36 return nil
39 } 37 }
40 38
41 // Print table
42 w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0) 39 w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
43 fmt.Fprintln(w, "NAME\tTYPE\tDOMAIN\tPORT") 40 fmt.Fprintln(w, "NAME\tTYPE\tDOMAIN\tPORT")
44 for name, app := range apps { 41 for name, app := range apps {
@@ -49,4 +46,5 @@ func runList(args []string) {
49 fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", name, app.Type, app.Domain, port) 46 fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", name, app.Type, app.Domain, port)
50 } 47 }
51 w.Flush() 48 w.Flush()
49 return nil
52} 50}