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/host/update.go | 80 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 cmd/deploy/host/update.go (limited to 'cmd/deploy/host/update.go') diff --git a/cmd/deploy/host/update.go b/cmd/deploy/host/update.go new file mode 100644 index 0000000..6f1b43b --- /dev/null +++ b/cmd/deploy/host/update.go @@ -0,0 +1,80 @@ +package host + +import ( + "bufio" + "fmt" + "os" + "strings" + + "github.com/bdw/deploy/internal/ssh" + "github.com/bdw/deploy/internal/state" + "github.com/spf13/cobra" +) + +var updateCmd = &cobra.Command{ + Use: "update", + Short: "Update VPS packages", + Long: "Run apt update && apt upgrade on the VPS", + RunE: runUpdate, +} + +func init() { + updateCmd.Flags().BoolP("yes", "y", false, "Skip confirmation prompt") +} + +func runUpdate(cmd *cobra.Command, args []string) error { + 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 (no default host set)") + } + + yes, _ := cmd.Flags().GetBool("yes") + if !yes { + fmt.Printf("This will run apt update && apt upgrade on %s\n", host) + fmt.Print("Continue? [y/N]: ") + reader := bufio.NewReader(os.Stdin) + response, _ := reader.ReadString('\n') + response = strings.TrimSpace(response) + if response != "y" && response != "Y" { + fmt.Println("Aborted.") + return nil + } + } + + fmt.Printf("Connecting to %s...\n", host) + + client, err := ssh.Connect(host) + if err != nil { + return fmt.Errorf("error connecting to VPS: %w", err) + } + defer client.Close() + + fmt.Println("\n-> Running apt update...") + if err := client.RunSudoStream("apt update"); err != nil { + return fmt.Errorf("error running apt update: %w", err) + } + + fmt.Println("\n-> Running apt upgrade...") + if err := client.RunSudoStream("DEBIAN_FRONTEND=noninteractive apt upgrade -y"); err != nil { + return fmt.Errorf("error running apt upgrade: %w", err) + } + + fmt.Println() + if output, err := client.Run("[ -f /var/run/reboot-required ] && echo 'yes' || echo 'no'"); err == nil { + if output == "yes\n" { + fmt.Println("Note: A reboot is required to complete the update.") + } + } + + fmt.Println("Update complete") + return nil +} -- cgit v1.2.3