package main import ( "fmt" "os" "text/tabwriter" "github.com/bdw/ship/internal/state" "github.com/spf13/cobra" ) var listCmd = &cobra.Command{ Use: "list", Short: "List all deployed apps and sites", RunE: runList, } func runList(cmd *cobra.Command, args []string) error { st, err := state.Load() if err != nil { return fmt.Errorf("error loading state: %w", err) } host := hostFlag if host == "" { host = st.GetDefaultHost() } if host == "" { return fmt.Errorf("--host is required") } apps := st.ListApps(host) if len(apps) == 0 { fmt.Printf("No deployments found for %s\n", host) return nil } 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() return nil }