mirror of
https://github.com/semaphoreui/semaphore.git
synced 2025-01-20 15:29:28 +01:00
fix(cli): bug with config path parameter
This commit is contained in:
parent
1b88630348
commit
9cf52616ec
@ -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)
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user