feat(cli): add default value for config option

This commit is contained in:
Denis Gukov 2022-01-21 21:27:48 +05:00
parent 01e56302f8
commit 4b024af095

View File

@ -27,24 +27,13 @@ var rootCmd = &cobra.Command{
Source code is available at https://github.com/ansible-semaphore/semaphore. Source code is available at https://github.com/ansible-semaphore/semaphore.
Complete documentation is available at https://ansible-semaphore.com.`, Complete documentation is available at https://ansible-semaphore.com.`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 && configPath == "" { _ = cmd.Help()
_ = cmd.Help() os.Exit(0)
os.Exit(0)
} else {
serviceCmd.Run(cmd, args)
}
}, },
} }
func Execute() { func Execute() {
args := os.Args[1:] rootCmd.PersistentFlags().StringVar(&configPath, "config", "/usr/local/etc/semaphore/config.json", "Configuration file path")
if len(args) == 2 && args[0] == "-config" {
configPath = args[1]
runService()
return
}
rootCmd.PersistentFlags().StringVar(&configPath, "config", "", "Configuration file path")
if err := rootCmd.Execute(); err != nil { if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
os.Exit(1) os.Exit(1)