summaryrefslogtreecommitdiffstats
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/config/config.go65
-rw-r--r--internal/state/state.go13
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 @@
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}
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
11type State struct { 11type 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
142func (s *State) GetDefaultHost() string {
143 return s.DefaultHost
144}
145
146// SetDefaultHost sets the default host
147func (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
141func statePath() string { 152func statePath() string {
142 home, err := os.UserHomeDir() 153 home, err := os.UserHomeDir()