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 /internal | |
| 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 'internal')
| -rw-r--r-- | internal/config/config.go | 65 | ||||
| -rw-r--r-- | internal/state/state.go | 13 |
2 files changed, 12 insertions, 66 deletions
diff --git a/internal/config/config.go b/internal/config/config.go deleted file mode 100644 index 8651aa8..0000000 --- a/internal/config/config.go +++ /dev/null | |||
| @@ -1,65 +0,0 @@ | |||
| 1 | package config | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "bufio" | ||
| 5 | "os" | ||
| 6 | "path/filepath" | ||
| 7 | "strings" | ||
| 8 | ) | ||
| 9 | |||
| 10 | // Config represents the user's configuration | ||
| 11 | type Config struct { | ||
| 12 | Host string | ||
| 13 | } | ||
| 14 | |||
| 15 | // Load reads config from ~/.config/deploy/config | ||
| 16 | func Load() (*Config, error) { | ||
| 17 | path := configPath() | ||
| 18 | |||
| 19 | // If file doesn't exist, return empty config | ||
| 20 | if _, err := os.Stat(path); os.IsNotExist(err) { | ||
| 21 | return &Config{}, nil | ||
| 22 | } | ||
| 23 | |||
| 24 | file, err := os.Open(path) | ||
| 25 | if err != nil { | ||
| 26 | return nil, err | ||
| 27 | } | ||
| 28 | defer file.Close() | ||
| 29 | |||
| 30 | cfg := &Config{} | ||
| 31 | scanner := bufio.NewScanner(file) | ||
| 32 | for scanner.Scan() { | ||
| 33 | line := strings.TrimSpace(scanner.Text()) | ||
| 34 | if line == "" || strings.HasPrefix(line, "#") { | ||
| 35 | continue | ||
| 36 | } | ||
| 37 | |||
| 38 | parts := strings.SplitN(line, ":", 2) | ||
| 39 | if len(parts) != 2 { | ||
| 40 | continue | ||
| 41 | } | ||
| 42 | |||
| 43 | key := strings.TrimSpace(parts[0]) | ||
| 44 | value := strings.TrimSpace(parts[1]) | ||
| 45 | |||
| 46 | switch key { | ||
| 47 | case "host": | ||
| 48 | cfg.Host = value | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | if err := scanner.Err(); err != nil { | ||
| 53 | return nil, err | ||
| 54 | } | ||
| 55 | |||
| 56 | return cfg, nil | ||
| 57 | } | ||
| 58 | |||
| 59 | func configPath() string { | ||
| 60 | home, err := os.UserHomeDir() | ||
| 61 | if err != nil { | ||
| 62 | return ".deploy-config" | ||
| 63 | } | ||
| 64 | return filepath.Join(home, ".config", "deploy", "config") | ||
| 65 | } | ||
diff --git a/internal/state/state.go b/internal/state/state.go index eb1dee8..def0bcf 100644 --- a/internal/state/state.go +++ b/internal/state/state.go | |||
| @@ -9,7 +9,8 @@ import ( | |||
| 9 | 9 | ||
| 10 | // State represents the entire local deployment state | 10 | // State represents the entire local deployment state |
| 11 | type State struct { | 11 | type State struct { |
| 12 | Hosts map[string]*Host `json:"hosts"` | 12 | DefaultHost string `json:"default_host,omitempty"` |
| 13 | Hosts map[string]*Host `json:"hosts"` | ||
| 13 | } | 14 | } |
| 14 | 15 | ||
| 15 | // Host represents deployment state for a single VPS | 16 | // Host represents deployment state for a single VPS |
| @@ -137,6 +138,16 @@ func (s *State) ListApps(host string) map[string]*App { | |||
| 137 | return h.Apps | 138 | return h.Apps |
| 138 | } | 139 | } |
| 139 | 140 | ||
| 141 | // GetDefaultHost returns the default host, or empty string if not set | ||
| 142 | func (s *State) GetDefaultHost() string { | ||
| 143 | return s.DefaultHost | ||
| 144 | } | ||
| 145 | |||
| 146 | // SetDefaultHost sets the default host | ||
| 147 | func (s *State) SetDefaultHost(host string) { | ||
| 148 | s.DefaultHost = host | ||
| 149 | } | ||
| 150 | |||
| 140 | // statePath returns the path to the state file | 151 | // statePath returns the path to the state file |
| 141 | func statePath() string { | 152 | func statePath() string { |
| 142 | home, err := os.UserHomeDir() | 153 | home, err := os.UserHomeDir() |
