Skip to content

Commit

Permalink
Merge pull request #28 from enkodr/fix-config-issue
Browse files Browse the repository at this point in the history
Fix issue when creating machine but config dir doesn't exist
  • Loading branch information
enkodr authored Jul 5, 2023
2 parents 781b102 + 0e171cf commit 4370a4d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,26 @@ func LoadConfig() (*Config, error) {
return loadConfigFromFile(cfgFile)
}

// Create config directory
createConfigDir()

// Otherwise, create a default config file
return createDefaultConfig(cfgFile)
}

// GetConfigFilePath returns the path to the config file
// getConfigFilePath returns the path to the config file
func getConfigFilePath() string {
home, _ := os.UserHomeDir()
return filepath.Join(home, cfgDir, "config.yaml")
}

// Create config directory
func createConfigDir() error {
home, _ := os.UserHomeDir()
dir := filepath.Join(home, cfgDir)
return os.MkdirAll(dir, 0755)
}

// configExists checks if the config file exists
func configExists(cfgFile string) bool {
_, err := os.Stat(cfgFile)
Expand Down

0 comments on commit 4370a4d

Please sign in to comment.