summaryrefslogtreecommitdiffstats
path: root/internal/config
diff options
context:
space:
mode:
authorbndw <ben@bdw.to>2025-12-28 09:21:08 -0800
committerbndw <ben@bdw.to>2025-12-28 09:21:08 -0800
commit13c2f9cffa624fdf498f3b61fab9d809b92e026e (patch)
tree4b25205ccd05e9e887376c10edb2f4069ea1d9d4 /internal/config
init
Diffstat (limited to 'internal/config')
-rw-r--r--internal/config/config.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
new file mode 100644
index 0000000..8651aa8
--- /dev/null
+++ b/internal/config/config.go
@@ -0,0 +1,65 @@
1package config
2
3import (
4 "bufio"
5 "os"
6 "path/filepath"
7 "strings"
8)
9
10// Config represents the user's configuration
11type Config struct {
12 Host string
13}
14
15// Load reads config from ~/.config/deploy/config
16func 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
59func 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}