From 87752492d0dc7df3cf78011d5ce315a3eb0cad51 Mon Sep 17 00:00:00 2001 From: bndw Date: Fri, 23 Jan 2026 21:52:50 -0800 Subject: 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. --- cmd/deploy/env/unset.go | 92 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 cmd/deploy/env/unset.go (limited to 'cmd/deploy/env/unset.go') diff --git a/cmd/deploy/env/unset.go b/cmd/deploy/env/unset.go new file mode 100644 index 0000000..65a8986 --- /dev/null +++ b/cmd/deploy/env/unset.go @@ -0,0 +1,92 @@ +package env + +import ( + "fmt" + + "github.com/bdw/deploy/internal/ssh" + "github.com/bdw/deploy/internal/state" + "github.com/spf13/cobra" +) + +var unsetCmd = &cobra.Command{ + Use: "unset KEY...", + Short: "Unset environment variable(s)", + Long: "Remove one or more environment variables from an app.", + Args: cobra.MinimumNArgs(2), + RunE: runUnset, +} + +func runUnset(cmd *cobra.Command, args []string) error { + name := args[0] + keys := args[1:] + + st, err := state.Load() + if err != nil { + return fmt.Errorf("error loading state: %w", err) + } + + host, _ := cmd.Flags().GetString("host") + if host == "" { + host = st.GetDefaultHost() + } + + if host == "" { + return fmt.Errorf("--host is required") + } + + app, err := st.GetApp(host, name) + if err != nil { + return err + } + + if app.Type != "app" { + return fmt.Errorf("env is only available for apps, not static sites") + } + + if app.Env == nil { + return fmt.Errorf("no environment variables set") + } + + changed := false + for _, key := range keys { + if _, exists := app.Env[key]; exists { + delete(app.Env, key) + changed = true + fmt.Printf("Unset %s\n", key) + } else { + fmt.Printf("Warning: %s not found\n", key) + } + } + + if !changed { + return nil + } + + if err := st.Save(); err != nil { + return fmt.Errorf("error saving state: %w", err) + } + + client, err := ssh.Connect(host) + if err != nil { + return fmt.Errorf("error connecting to VPS: %w", err) + } + defer client.Close() + + fmt.Println("-> Updating environment file on VPS...") + envFilePath := fmt.Sprintf("/etc/deploy/env/%s.env", name) + envContent := "" + for k, v := range app.Env { + envContent += fmt.Sprintf("%s=%s\n", k, v) + } + if err := client.WriteSudoFile(envFilePath, envContent); err != nil { + return fmt.Errorf("error updating env file: %w", err) + } + + fmt.Println("-> Restarting service...") + if _, err := client.RunSudo(fmt.Sprintf("systemctl restart %s", name)); err != nil { + return fmt.Errorf("error restarting service: %w", err) + } + + fmt.Println("Environment variables updated successfully") + return nil +} -- cgit v1.2.3