package main import ( "flag" "fmt" "os" "text/tabwriter" "github.com/bdw/deploy/internal/config" "github.com/bdw/deploy/internal/state" ) 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) // Get host from flag or config if *host == "" { cfg, err := config.Load() if err != nil { fmt.Fprintf(os.Stderr, "Error loading config: %v\n", err) os.Exit(1) } *host = cfg.Host } if *host == "" { fmt.Fprintf(os.Stderr, "Error: --host is required\n") fs.Usage() os.Exit(1) } // Load state st, err := state.Load() if err != nil { fmt.Fprintf(os.Stderr, "Error loading state: %v\n", err) os.Exit(1) } apps := st.ListApps(*host) if len(apps) == 0 { fmt.Printf("No deployments found for %s\n", *host) return } // Print table w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0) fmt.Fprintln(w, "NAME\tTYPE\tDOMAIN\tPORT") for name, app := range apps { port := "" if app.Type == "app" { port = fmt.Sprintf(":%d", app.Port) } fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", name, app.Type, app.Domain, port) } w.Flush() }