提交 e5d0ae37 编写于 作者: M Maximilian Zirps

showing version even if no config file specified #166

上级 be300f6a
...@@ -26,20 +26,21 @@ var rootCmd = &cobra.Command{ ...@@ -26,20 +26,21 @@ var rootCmd = &cobra.Command{
Long: `jcli is Jenkins CLI which could help with your multiple Jenkins, Long: `jcli is Jenkins CLI which could help with your multiple Jenkins,
Manage your Jenkins and your pipelines Manage your Jenkins and your pipelines
More information could found at https://jenkins-zh.cn`, More information could found at https://jenkins-zh.cn`,
Run: func(_ *cobra.Command, _ []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Jenkins CLI (jcli) manage your Jenkins") cmd.Println("Jenkins CLI (jcli) manage your Jenkins")
if rootOptions.Version {
cmd.Printf("Version: %s\n", app.GetVersion())
cmd.Printf("Commit: %s\n", app.GetCommit())
}
if rootOptions.Jenkins != "" {
current := getCurrentJenkinsFromOptionsOrDie() current := getCurrentJenkinsFromOptionsOrDie()
if current != nil { if current != nil {
fmt.Println("Current Jenkins is:", current.Name) cmd.Println("Current Jenkins is:", current.Name)
} else { } else {
fmt.Println("Cannot found the configuration") cmd.Println("Cannot found the configuration")
} }
if rootOptions.Version {
fmt.Printf("Version: %s\n", app.GetVersion())
fmt.Printf("Commit: %s\n", app.GetCommit())
} }
}, },
} }
...@@ -62,6 +63,9 @@ func init() { ...@@ -62,6 +63,9 @@ func init() {
} }
func initConfig() { func initConfig() {
if rootOptions.Version && rootCmd.Flags().NFlag() == 1 {
return
}
if rootOptions.ConfigFile == "" { if rootOptions.ConfigFile == "" {
if err := loadDefaultConfig(); err != nil { if err := loadDefaultConfig(); err != nil {
configLoadErrorHandle(err) configLoadErrorHandle(err)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册