fix(cli): bug with config path parameter

This commit is contained in:
Denis Gukov 2022-01-24 01:13:29 +05:00
parent 1b88630348
commit 9cf52616ec
2 changed files with 20 additions and 10 deletions

View File

@ -33,7 +33,7 @@ Complete documentation is available at https://ansible-semaphore.com.`,
}
func Execute() {
rootCmd.PersistentFlags().StringVar(&configPath, "config", "/usr/local/etc/semaphore/config.json", "Configuration file path")
rootCmd.PersistentFlags().StringVar(&configPath, "config", "", "Configuration file path")
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)

View File

@ -150,22 +150,32 @@ func loadConfig(configPath string) {
//var usedPath string
if configPath == "" {
// if no configPath look in the cwd
cwd, err := os.Getwd()
exitOnConfigError(err)
defaultPath := path.Join(cwd, "config.json")
file, err := os.Open(defaultPath)
paths := []string{
path.Join(cwd, "config.json"),
"/usr/local/etc/semaphore/config.json",
}
for _, p := range paths {
_, err = os.Stat(p)
if err != nil {
continue
}
var file *os.File
file, err = os.Open(p)
if err != nil {
continue
}
decodeConfig(file)
break
}
exitOnConfigError(err)
decodeConfig(file)
//usedPath = defaultPath
} else {
path := configPath
file, err := os.Open(path)
p := configPath
file, err := os.Open(p)
exitOnConfigError(err)
decodeConfig(file)
//usedPath = path
}
//fmt.Println("Using config file: " + usedPath)
}
func validateConfig() {