From 87752492d0dc7df3cf78011d5ce315a3eb0cad51 Mon Sep 17 00:00:00 2001 From: bndw Date: Fri, 23 Jan 2026 21:52:50 -0800 Subject: 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. --- cmd/deploy/list.go | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'cmd/deploy/list.go') 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 @@ package main import ( - "flag" "fmt" "os" "text/tabwriter" "github.com/bdw/deploy/internal/state" + "github.com/spf13/cobra" ) -func runList(args []string) { - fs := flag.NewFlagSet("list", flag.ExitOnError) - host := fs.String("host", "", "VPS host (SSH config alias or user@host)") - fs.Parse(args) +var listCmd = &cobra.Command{ + Use: "list", + Short: "List all deployed apps and sites", + RunE: runList, +} - // Load state +func runList(cmd *cobra.Command, args []string) error { st, err := state.Load() if err != nil { - fmt.Fprintf(os.Stderr, "Error loading state: %v\n", err) - os.Exit(1) + return fmt.Errorf("error loading state: %w", err) } - // Get host from flag or state default - if *host == "" { - *host = st.GetDefaultHost() + host := hostFlag + if host == "" { + host = st.GetDefaultHost() } - if *host == "" { - fmt.Fprintf(os.Stderr, "Error: --host is required\n") - fs.Usage() - os.Exit(1) + if host == "" { + return fmt.Errorf("--host is required") } - apps := st.ListApps(*host) + apps := st.ListApps(host) if len(apps) == 0 { - fmt.Printf("No deployments found for %s\n", *host) - return + fmt.Printf("No deployments found for %s\n", host) + return nil } - // Print table w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0) fmt.Fprintln(w, "NAME\tTYPE\tDOMAIN\tPORT") for name, app := range apps { @@ -49,4 +46,5 @@ func runList(args []string) { fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", name, app.Type, app.Domain, port) } w.Flush() + return nil } -- cgit v1.2.3