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/manage.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/manage.go')
| -rw-r--r-- | cmd/deploy/manage.go | 93 |
1 files changed, 36 insertions, 57 deletions
diff --git a/cmd/deploy/manage.go b/cmd/deploy/manage.go index 3cee1f4..1f52b92 100644 --- a/cmd/deploy/manage.go +++ b/cmd/deploy/manage.go | |||
| @@ -5,7 +5,6 @@ import ( | |||
| 5 | "fmt" | 5 | "fmt" |
| 6 | "os" | 6 | "os" |
| 7 | 7 | ||
| 8 | "github.com/bdw/deploy/internal/config" | ||
| 9 | "github.com/bdw/deploy/internal/ssh" | 8 | "github.com/bdw/deploy/internal/ssh" |
| 10 | "github.com/bdw/deploy/internal/state" | 9 | "github.com/bdw/deploy/internal/state" |
| 11 | ) | 10 | ) |
| @@ -23,14 +22,16 @@ func runRemove(args []string) { | |||
| 23 | 22 | ||
| 24 | name := fs.Args()[0] | 23 | name := fs.Args()[0] |
| 25 | 24 | ||
| 26 | // Get host from flag or config | 25 | // Load state |
| 26 | st, err := state.Load() | ||
| 27 | if err != nil { | ||
| 28 | fmt.Fprintf(os.Stderr, "Error loading state: %v\n", err) | ||
| 29 | os.Exit(1) | ||
| 30 | } | ||
| 31 | |||
| 32 | // Get host from flag or state default | ||
| 27 | if *host == "" { | 33 | if *host == "" { |
| 28 | cfg, err := config.Load() | 34 | *host = st.GetDefaultHost() |
| 29 | if err != nil { | ||
| 30 | fmt.Fprintf(os.Stderr, "Error loading config: %v\n", err) | ||
| 31 | os.Exit(1) | ||
| 32 | } | ||
| 33 | *host = cfg.Host | ||
| 34 | } | 35 | } |
| 35 | 36 | ||
| 36 | if *host == "" { | 37 | if *host == "" { |
| @@ -39,13 +40,6 @@ func runRemove(args []string) { | |||
| 39 | os.Exit(1) | 40 | os.Exit(1) |
| 40 | } | 41 | } |
| 41 | 42 | ||
| 42 | // Load state | ||
| 43 | st, err := state.Load() | ||
| 44 | if err != nil { | ||
| 45 | fmt.Fprintf(os.Stderr, "Error loading state: %v\n", err) | ||
| 46 | os.Exit(1) | ||
| 47 | } | ||
| 48 | |||
| 49 | // Get app info | 43 | // Get app info |
| 50 | app, err := st.GetApp(*host, name) | 44 | app, err := st.GetApp(*host, name) |
| 51 | if err != nil { | 45 | if err != nil { |
| @@ -128,14 +122,16 @@ func runLogs(args []string) { | |||
| 128 | 122 | ||
| 129 | name := fs.Args()[0] | 123 | name := fs.Args()[0] |
| 130 | 124 | ||
| 131 | // Get host from flag or config | 125 | // Load state |
| 126 | st, err := state.Load() | ||
| 127 | if err != nil { | ||
| 128 | fmt.Fprintf(os.Stderr, "Error loading state: %v\n", err) | ||
| 129 | os.Exit(1) | ||
| 130 | } | ||
| 131 | |||
| 132 | // Get host from flag or state default | ||
| 132 | if *host == "" { | 133 | if *host == "" { |
| 133 | cfg, err := config.Load() | 134 | *host = st.GetDefaultHost() |
| 134 | if err != nil { | ||
| 135 | fmt.Fprintf(os.Stderr, "Error loading config: %v\n", err) | ||
| 136 | os.Exit(1) | ||
| 137 | } | ||
| 138 | *host = cfg.Host | ||
| 139 | } | 135 | } |
| 140 | 136 | ||
| 141 | if *host == "" { | 137 | if *host == "" { |
| @@ -144,13 +140,6 @@ func runLogs(args []string) { | |||
| 144 | os.Exit(1) | 140 | os.Exit(1) |
| 145 | } | 141 | } |
| 146 | 142 | ||
| 147 | // Load state to verify app exists | ||
| 148 | st, err := state.Load() | ||
| 149 | if err != nil { | ||
| 150 | fmt.Fprintf(os.Stderr, "Error loading state: %v\n", err) | ||
| 151 | os.Exit(1) | ||
| 152 | } | ||
| 153 | |||
| 154 | app, err := st.GetApp(*host, name) | 143 | app, err := st.GetApp(*host, name) |
| 155 | if err != nil { | 144 | if err != nil { |
| 156 | fmt.Fprintf(os.Stderr, "Error: %v\n", err) | 145 | fmt.Fprintf(os.Stderr, "Error: %v\n", err) |
| @@ -207,14 +196,16 @@ func runStatus(args []string) { | |||
| 207 | 196 | ||
| 208 | name := fs.Args()[0] | 197 | name := fs.Args()[0] |
| 209 | 198 | ||
| 210 | // Get host from flag or config | 199 | // Load state |
| 200 | st, err := state.Load() | ||
| 201 | if err != nil { | ||
| 202 | fmt.Fprintf(os.Stderr, "Error loading state: %v\n", err) | ||
| 203 | os.Exit(1) | ||
| 204 | } | ||
| 205 | |||
| 206 | // Get host from flag or state default | ||
| 211 | if *host == "" { | 207 | if *host == "" { |
| 212 | cfg, err := config.Load() | 208 | *host = st.GetDefaultHost() |
| 213 | if err != nil { | ||
| 214 | fmt.Fprintf(os.Stderr, "Error loading config: %v\n", err) | ||
| 215 | os.Exit(1) | ||
| 216 | } | ||
| 217 | *host = cfg.Host | ||
| 218 | } | 209 | } |
| 219 | 210 | ||
| 220 | if *host == "" { | 211 | if *host == "" { |
| @@ -223,13 +214,6 @@ func runStatus(args []string) { | |||
| 223 | os.Exit(1) | 214 | os.Exit(1) |
| 224 | } | 215 | } |
| 225 | 216 | ||
| 226 | // Load state to verify app exists | ||
| 227 | st, err := state.Load() | ||
| 228 | if err != nil { | ||
| 229 | fmt.Fprintf(os.Stderr, "Error loading state: %v\n", err) | ||
| 230 | os.Exit(1) | ||
| 231 | } | ||
| 232 | |||
| 233 | app, err := st.GetApp(*host, name) | 217 | app, err := st.GetApp(*host, name) |
| 234 | if err != nil { | 218 | if err != nil { |
| 235 | fmt.Fprintf(os.Stderr, "Error: %v\n", err) | 219 | fmt.Fprintf(os.Stderr, "Error: %v\n", err) |
| @@ -274,14 +258,16 @@ func runRestart(args []string) { | |||
| 274 | 258 | ||
| 275 | name := fs.Args()[0] | 259 | name := fs.Args()[0] |
| 276 | 260 | ||
| 277 | // Get host from flag or config | 261 | // Load state |
| 262 | st, err := state.Load() | ||
| 263 | if err != nil { | ||
| 264 | fmt.Fprintf(os.Stderr, "Error loading state: %v\n", err) | ||
| 265 | os.Exit(1) | ||
| 266 | } | ||
| 267 | |||
| 268 | // Get host from flag or state default | ||
| 278 | if *host == "" { | 269 | if *host == "" { |
| 279 | cfg, err := config.Load() | 270 | *host = st.GetDefaultHost() |
| 280 | if err != nil { | ||
| 281 | fmt.Fprintf(os.Stderr, "Error loading config: %v\n", err) | ||
| 282 | os.Exit(1) | ||
| 283 | } | ||
| 284 | *host = cfg.Host | ||
| 285 | } | 271 | } |
| 286 | 272 | ||
| 287 | if *host == "" { | 273 | if *host == "" { |
| @@ -290,13 +276,6 @@ func runRestart(args []string) { | |||
| 290 | os.Exit(1) | 276 | os.Exit(1) |
| 291 | } | 277 | } |
| 292 | 278 | ||
| 293 | // Load state to verify app exists | ||
| 294 | st, err := state.Load() | ||
| 295 | if err != nil { | ||
| 296 | fmt.Fprintf(os.Stderr, "Error loading state: %v\n", err) | ||
| 297 | os.Exit(1) | ||
| 298 | } | ||
| 299 | |||
| 300 | app, err := st.GetApp(*host, name) | 279 | app, err := st.GetApp(*host, name) |
| 301 | if err != nil { | 280 | if err != nil { |
| 302 | fmt.Fprintf(os.Stderr, "Error: %v\n", err) | 281 | fmt.Fprintf(os.Stderr, "Error: %v\n", err) |
