From b5d97f633c960a826577fd80cb1d29e392dce34b Mon Sep 17 00:00:00 2001 From: bndw Date: Fri, 23 Jan 2026 21:10:04 -0800 Subject: Move default host from config file to state.json Instead of a separate ~/.config/deploy/config file, the default host is now stored as default_host in state.json. This simplifies the config and keeps all state in one place. The init command now automatically sets the default host if none is configured. --- cmd/deploy/init.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'cmd/deploy/init.go') diff --git a/cmd/deploy/init.go b/cmd/deploy/init.go index 72c7d53..1713879 100644 --- a/cmd/deploy/init.go +++ b/cmd/deploy/init.go @@ -6,7 +6,6 @@ import ( "os" "strings" - "github.com/bdw/deploy/internal/config" "github.com/bdw/deploy/internal/ssh" "github.com/bdw/deploy/internal/state" ) @@ -16,14 +15,16 @@ func runInit(args []string) { host := fs.String("host", "", "VPS host (SSH config alias or user@host)") fs.Parse(args) - // Get host from flag or config + // Load state + st, err := state.Load() + if err != nil { + fmt.Fprintf(os.Stderr, "Error loading state: %v\n", err) + os.Exit(1) + } + + // Get host from flag or state default if *host == "" { - cfg, err := config.Load() - if err != nil { - fmt.Fprintf(os.Stderr, "Error loading config: %v\n", err) - os.Exit(1) - } - *host = cfg.Host + *host = st.GetDefaultHost() } if *host == "" { @@ -115,13 +116,12 @@ import /etc/caddy/sites-enabled/* fmt.Println(" ✓ Caddy is active") } - // Initialize local state if needed - st, err := state.Load() - if err != nil { - fmt.Fprintf(os.Stderr, "Error loading state: %v\n", err) - os.Exit(1) - } + // Update state st.GetHost(*host) // Ensure host exists in state + if st.GetDefaultHost() == "" { + st.SetDefaultHost(*host) + fmt.Printf(" Set %s as default host\n", *host) + } if err := st.Save(); err != nil { fmt.Fprintf(os.Stderr, "Error saving state: %v\n", err) os.Exit(1) -- cgit v1.2.3