diff options
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 | } | ||
