Can now set custom config path flag when starting daemon
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
type AppConfig struct {
|
||||
Storage struct {
|
||||
AppDataDir string `json:"app_data_dir"`
|
||||
InstallDir string `json:"install_dir"`
|
||||
InstancesDir string `json:"instances_dir"`
|
||||
BackupDir string `json:"backup_dir"`
|
||||
@@ -16,18 +17,18 @@ type AppConfig struct {
|
||||
} `json:"storage"`
|
||||
|
||||
Daemon struct {
|
||||
// UseNixOs bool `json:"use_nixos"`
|
||||
ListenAddress string `json:"listen_address"`
|
||||
}
|
||||
|
||||
Instances map[string]VsServerConfigOptions `json:"instances"`
|
||||
}
|
||||
|
||||
func DefaultConfig() *AppConfig {
|
||||
func CreateConfigWithDefaults(configPath string) *AppConfig {
|
||||
home, _ := os.UserHomeDir()
|
||||
basePath := filepath.Join(home, ".local", "share", "vssm")
|
||||
|
||||
cfg := &AppConfig{}
|
||||
cfg.Storage.AppDataDir = basePath
|
||||
cfg.Storage.InstallDir = filepath.Join(basePath, "installs")
|
||||
cfg.Storage.InstancesDir = filepath.Join(basePath, "instances")
|
||||
cfg.Storage.BackupDir = filepath.Join(basePath, "backups")
|
||||
@@ -42,7 +43,7 @@ func DefaultConfig() *AppConfig {
|
||||
|
||||
func LoadOrCreateConfig(configPath string) (*AppConfig, error) {
|
||||
if _, err := os.Stat(configPath); os.IsNotExist(err) {
|
||||
cfg := DefaultConfig()
|
||||
cfg := CreateConfigWithDefaults(configPath)
|
||||
|
||||
if err := os.MkdirAll(filepath.Dir(configPath), 0755); err != nil {
|
||||
return nil, fmt.Errorf("Failed to create config directory: %w", err)
|
||||
@@ -69,6 +70,7 @@ func LoadOrCreateConfig(configPath string) (*AppConfig, error) {
|
||||
}
|
||||
|
||||
dirs := []string{
|
||||
cfg.Storage.AppDataDir,
|
||||
cfg.Storage.InstallDir,
|
||||
cfg.Storage.InstancesDir,
|
||||
cfg.Storage.BackupDir,
|
||||
|
||||
Reference in New Issue
Block a user