summaryrefslogtreecommitdiffstats
path: root/cmd/deploy/logs.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/logs.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/logs.go')
-rw-r--r--cmd/deploy/logs.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/cmd/deploy/logs.go b/cmd/deploy/logs.go
new file mode 100644
index 0000000..2b016b8
--- /dev/null
+++ b/cmd/deploy/logs.go
@@ -0,0 +1,75 @@
1package main
2
3import (
4 "fmt"
5
6 "github.com/bdw/deploy/internal/ssh"
7 "github.com/bdw/deploy/internal/state"
8 "github.com/spf13/cobra"
9)
10
11var logsCmd = &cobra.Command{
12 Use: "logs <app>",
13 Short: "View logs for a deployment",
14 Args: cobra.ExactArgs(1),
15 RunE: runLogs,
16}
17
18func init() {
19 logsCmd.Flags().BoolP("follow", "f", false, "Follow logs")
20 logsCmd.Flags().IntP("lines", "n", 50, "Number of lines to show")
21}
22
23func runLogs(cmd *cobra.Command, args []string) error {
24 name := args[0]
25 follow, _ := cmd.Flags().GetBool("follow")
26 lines, _ := cmd.Flags().GetInt("lines")
27
28 st, err := state.Load()
29 if err != nil {
30 return fmt.Errorf("error loading state: %w", err)
31 }
32
33 host := hostFlag
34 if host == "" {
35 host = st.GetDefaultHost()
36 }
37
38 if host == "" {
39 return fmt.Errorf("--host is required")
40 }
41
42 app, err := st.GetApp(host, name)
43 if err != nil {
44 return err
45 }
46
47 if app.Type != "app" {
48 return fmt.Errorf("logs are only available for apps, not static sites")
49 }
50
51 client, err := ssh.Connect(host)
52 if err != nil {
53 return fmt.Errorf("error connecting to VPS: %w", err)
54 }
55 defer client.Close()
56
57 journalCmd := fmt.Sprintf("journalctl -u %s -n %d", name, lines)
58 if follow {
59 journalCmd += " -f"
60 }
61
62 if follow {
63 if err := client.RunStream(journalCmd); err != nil {
64 return fmt.Errorf("error fetching logs: %w", err)
65 }
66 } else {
67 output, err := client.Run(journalCmd)
68 if err != nil {
69 return fmt.Errorf("error fetching logs: %w", err)
70 }
71 fmt.Print(output)
72 }
73
74 return nil
75}