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/config | |
| 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/config')
| -rw-r--r-- | internal/config/config.go | 65 |
1 files changed, 0 insertions, 65 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 | } | ||
