From b5d97f633c960a826577fd80cb1d29e392dce34b Mon Sep 17 00:00:00 2001 From: bndw Date: Fri, 23 Jan 2026 21:10:04 -0800 Subject: 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. --- internal/config/config.go | 65 ----------------------------------------------- internal/state/state.go | 13 +++++++++- 2 files changed, 12 insertions(+), 66 deletions(-) delete mode 100644 internal/config/config.go (limited to 'internal') 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 @@ -package config - -import ( - "bufio" - "os" - "path/filepath" - "strings" -) - -// Config represents the user's configuration -type Config struct { - Host string -} - -// Load reads config from ~/.config/deploy/config -func Load() (*Config, error) { - path := configPath() - - // If file doesn't exist, return empty config - if _, err := os.Stat(path); os.IsNotExist(err) { - return &Config{}, nil - } - - file, err := os.Open(path) - if err != nil { - return nil, err - } - defer file.Close() - - cfg := &Config{} - scanner := bufio.NewScanner(file) - for scanner.Scan() { - line := strings.TrimSpace(scanner.Text()) - if line == "" || strings.HasPrefix(line, "#") { - continue - } - - parts := strings.SplitN(line, ":", 2) - if len(parts) != 2 { - continue - } - - key := strings.TrimSpace(parts[0]) - value := strings.TrimSpace(parts[1]) - - switch key { - case "host": - cfg.Host = value - } - } - - if err := scanner.Err(); err != nil { - return nil, err - } - - return cfg, nil -} - -func configPath() string { - home, err := os.UserHomeDir() - if err != nil { - return ".deploy-config" - } - return filepath.Join(home, ".config", "deploy", "config") -} 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 ( // State represents the entire local deployment state type State struct { - Hosts map[string]*Host `json:"hosts"` + DefaultHost string `json:"default_host,omitempty"` + Hosts map[string]*Host `json:"hosts"` } // Host represents deployment state for a single VPS @@ -137,6 +138,16 @@ func (s *State) ListApps(host string) map[string]*App { return h.Apps } +// GetDefaultHost returns the default host, or empty string if not set +func (s *State) GetDefaultHost() string { + return s.DefaultHost +} + +// SetDefaultHost sets the default host +func (s *State) SetDefaultHost(host string) { + s.DefaultHost = host +} + // statePath returns the path to the state file func statePath() string { home, err := os.UserHomeDir() -- cgit v1.2.3