diff options
| author | bndw <ben@bdw.to> | 2026-01-23 21:10:04 -0800 |
|---|---|---|
| committer | bndw <ben@bdw.to> | 2026-01-23 21:10:04 -0800 |
| commit | b5d97f633c960a826577fd80cb1d29e392dce34b (patch) | |
| tree | 312b934506f835bcc77c4dcbb9e38a27efbf1528 /cmd/deploy/init.go | |
| parent | 98b9af372025595e8a4255538e2836e019311474 (diff) | |
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.
Diffstat (limited to 'cmd/deploy/init.go')
| -rw-r--r-- | cmd/deploy/init.go | 28 |
1 files changed, 14 insertions, 14 deletions
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 ( | |||
| 6 | "os" | 6 | "os" |
| 7 | "strings" | 7 | "strings" |
| 8 | 8 | ||
| 9 | "github.com/bdw/deploy/internal/config" | ||
| 10 | "github.com/bdw/deploy/internal/ssh" | 9 | "github.com/bdw/deploy/internal/ssh" |
| 11 | "github.com/bdw/deploy/internal/state" | 10 | "github.com/bdw/deploy/internal/state" |
| 12 | ) | 11 | ) |
| @@ -16,14 +15,16 @@ func runInit(args []string) { | |||
| 16 | host := fs.String("host", "", "VPS host (SSH config alias or user@host)") | 15 | host := fs.String("host", "", "VPS host (SSH config alias or user@host)") |
| 17 | fs.Parse(args) | 16 | fs.Parse(args) |
| 18 | 17 | ||
| 19 | // Get host from flag or config | 18 | // Load state |
| 19 | st, err := state.Load() | ||
| 20 | if err != nil { | ||
| 21 | fmt.Fprintf(os.Stderr, "Error loading state: %v\n", err) | ||
| 22 | os.Exit(1) | ||
| 23 | } | ||
| 24 | |||
| 25 | // Get host from flag or state default | ||
| 20 | if *host == "" { | 26 | if *host == "" { |
| 21 | cfg, err := config.Load() | 27 | *host = st.GetDefaultHost() |
| 22 | if err != nil { | ||
| 23 | fmt.Fprintf(os.Stderr, "Error loading config: %v\n", err) | ||
| 24 | os.Exit(1) | ||
| 25 | } | ||
| 26 | *host = cfg.Host | ||
| 27 | } | 28 | } |
| 28 | 29 | ||
| 29 | if *host == "" { | 30 | if *host == "" { |
| @@ -115,13 +116,12 @@ import /etc/caddy/sites-enabled/* | |||
| 115 | fmt.Println(" ✓ Caddy is active") | 116 | fmt.Println(" ✓ Caddy is active") |
| 116 | } | 117 | } |
| 117 | 118 | ||
| 118 | // Initialize local state if needed | 119 | // Update state |
| 119 | st, err := state.Load() | ||
| 120 | if err != nil { | ||
| 121 | fmt.Fprintf(os.Stderr, "Error loading state: %v\n", err) | ||
| 122 | os.Exit(1) | ||
| 123 | } | ||
| 124 | st.GetHost(*host) // Ensure host exists in state | 120 | st.GetHost(*host) // Ensure host exists in state |
| 121 | if st.GetDefaultHost() == "" { | ||
| 122 | st.SetDefaultHost(*host) | ||
| 123 | fmt.Printf(" Set %s as default host\n", *host) | ||
| 124 | } | ||
| 125 | if err := st.Save(); err != nil { | 125 | if err := st.Save(); err != nil { |
| 126 | fmt.Fprintf(os.Stderr, "Error saving state: %v\n", err) | 126 | fmt.Fprintf(os.Stderr, "Error saving state: %v\n", err) |
| 127 | os.Exit(1) | 127 | os.Exit(1) |
