summaryrefslogtreecommitdiffstats
path: root/cmd/deploy/list.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/deploy/list.go')
-rw-r--r--cmd/deploy/list.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/cmd/deploy/list.go b/cmd/deploy/list.go
new file mode 100644
index 0000000..b74cf35
--- /dev/null
+++ b/cmd/deploy/list.go
@@ -0,0 +1,58 @@
1package main
2
3import (
4 "flag"
5 "fmt"
6 "os"
7 "text/tabwriter"
8
9 "github.com/bdw/deploy/internal/config"
10 "github.com/bdw/deploy/internal/state"
11)
12
13func runList(args []string) {
14 fs := flag.NewFlagSet("list", flag.ExitOnError)
15 host := fs.String("host", "", "VPS host (SSH config alias or user@host)")
16 fs.Parse(args)
17
18 // Get host from flag or config
19 if *host == "" {
20 cfg, err := config.Load()
21 if err != nil {
22 fmt.Fprintf(os.Stderr, "Error loading config: %v\n", err)
23 os.Exit(1)
24 }
25 *host = cfg.Host
26 }
27
28 if *host == "" {
29 fmt.Fprintf(os.Stderr, "Error: --host is required\n")
30 fs.Usage()
31 os.Exit(1)
32 }
33
34 // Load state
35 st, err := state.Load()
36 if err != nil {
37 fmt.Fprintf(os.Stderr, "Error loading state: %v\n", err)
38 os.Exit(1)
39 }
40
41 apps := st.ListApps(*host)
42 if len(apps) == 0 {
43 fmt.Printf("No deployments found for %s\n", *host)
44 return
45 }
46
47 // Print table
48 w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
49 fmt.Fprintln(w, "NAME\tTYPE\tDOMAIN\tPORT")
50 for name, app := range apps {
51 port := ""
52 if app.Type == "app" {
53 port = fmt.Sprintf(":%d", app.Port)
54 }
55 fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", name, app.Type, app.Domain, port)
56 }
57 w.Flush()
58}