summaryrefslogtreecommitdiffstats
path: root/cmd/ship/env/unset.go
diff options
context:
space:
mode:
authorClawd <ai@clawd.bot>2026-02-17 08:11:19 -0800
committerClawd <ai@clawd.bot>2026-02-17 08:11:19 -0800
commit6f02ec84a8299fc5577f147cc8741c8a4b162b64 (patch)
tree020f3690e92732dcba723be0cfaef649f46de137 /cmd/ship/env/unset.go
parent4b5a2656df13181b637c59c29ff31751e11cf22a (diff)
parent05ea98df57599775c1d5bfea336012b075531670 (diff)
Merge agent-mode: v2 rewrite complete
- Removed all v1 code (-2800 lines) - Simplified state to just default_host + base_domain - Atomic port allocation via flock - --container-port flag for Docker - Custom domains shown in ship list - Caddyfiles preserved on redeploy - JSON output by default, --pretty for humans
Diffstat (limited to 'cmd/ship/env/unset.go')
-rw-r--r--cmd/ship/env/unset.go95
1 files changed, 0 insertions, 95 deletions
diff --git a/cmd/ship/env/unset.go b/cmd/ship/env/unset.go
deleted file mode 100644
index 8292f42..0000000
--- a/cmd/ship/env/unset.go
+++ /dev/null
@@ -1,95 +0,0 @@
1package env
2
3import (
4 "fmt"
5
6 "github.com/bdw/ship/internal/ssh"
7 "github.com/bdw/ship/internal/state"
8 "github.com/spf13/cobra"
9)
10
11var unsetCmd = &cobra.Command{
12 Use: "unset <app> KEY...",
13 Short: "Unset environment variable(s)",
14 Long: "Remove one or more environment variables from an app.",
15 Args: cobra.MinimumNArgs(2),
16 RunE: runUnset,
17}
18
19func runUnset(cmd *cobra.Command, args []string) error {
20 name := args[0]
21 if err := state.ValidateName(name); err != nil {
22 return err
23 }
24 keys := args[1:]
25
26 st, err := state.Load()
27 if err != nil {
28 return fmt.Errorf("error loading state: %w", err)
29 }
30
31 host, _ := cmd.Flags().GetString("host")
32 if host == "" {
33 host = st.GetDefaultHost()
34 }
35
36 if host == "" {
37 return fmt.Errorf("--host is required")
38 }
39
40 app, err := st.GetApp(host, name)
41 if err != nil {
42 return err
43 }
44
45 if app.Type != "app" {
46 return fmt.Errorf("env is only available for apps, not static sites")
47 }
48
49 if app.Env == nil {
50 return fmt.Errorf("no environment variables set")
51 }
52
53 changed := false
54 for _, key := range keys {
55 if _, exists := app.Env[key]; exists {
56 delete(app.Env, key)
57 changed = true
58 fmt.Printf("Unset %s\n", key)
59 } else {
60 fmt.Printf("Warning: %s not found\n", key)
61 }
62 }
63
64 if !changed {
65 return nil
66 }
67
68 if err := st.Save(); err != nil {
69 return fmt.Errorf("error saving state: %w", err)
70 }
71
72 client, err := ssh.Connect(host)
73 if err != nil {
74 return fmt.Errorf("error connecting to VPS: %w", err)
75 }
76 defer client.Close()
77
78 fmt.Println("-> Updating environment file on VPS...")
79 envFilePath := fmt.Sprintf("/etc/ship/env/%s.env", name)
80 envContent := ""
81 for k, v := range app.Env {
82 envContent += fmt.Sprintf("%s=%s\n", k, v)
83 }
84 if err := client.WriteSudoFile(envFilePath, envContent); err != nil {
85 return fmt.Errorf("error updating env file: %w", err)
86 }
87
88 fmt.Println("-> Restarting service...")
89 if _, err := client.RunSudo(fmt.Sprintf("systemctl restart %s", name)); err != nil {
90 return fmt.Errorf("error restarting service: %w", err)
91 }
92
93 fmt.Println("Environment variables updated successfully")
94 return nil
95}