diff --git a/app/cmd/casc_open.go b/app/cmd/casc_open.go index b2943636dc8b8c3ef6dc04385076fb49103c65d6..d80db6801b893181cbc1c593a8352d4391c531b2 100644 --- a/app/cmd/casc_open.go +++ b/app/cmd/casc_open.go @@ -2,7 +2,9 @@ package cmd import ( "fmt" + "github.com/jenkins-zh/jenkins-cli/app/i18n" + "github.com/jenkins-zh/jenkins-cli/util" "github.com/spf13/cobra" ) diff --git a/app/cmd/center_start.go b/app/cmd/center_start.go index a9ea218fb04a1d0730457ef8e368349a4ca0b1de..bf9e8f2f4dc1623206220f459357a212cb3dc73e 100644 --- a/app/cmd/center_start.go +++ b/app/cmd/center_start.go @@ -2,11 +2,11 @@ package cmd import ( "fmt" + "os" "github.com/jenkins-zh/jenkins-cli/app/i18n" "github.com/jenkins-zh/jenkins-cli/util" "github.com/mitchellh/go-homedir" - "os" "github.com/spf13/cobra" ) diff --git a/app/cmd/config.go b/app/cmd/config.go index ebaa1c7cdf3a6e209aea7e2ed82e58787ec223ac..55e0f56bfe671e56b07674d0973a5bdc0c300b3a 100644 --- a/app/cmd/config.go +++ b/app/cmd/config.go @@ -31,13 +31,18 @@ var configCmd = &cobra.Command{ Aliases: []string{"cfg"}, Short: i18n.T("Manage the config of jcli"), Long: i18n.T("Manage the config of jcli"), - Run: func(cmd *cobra.Command, _ []string) { + RunE: func(cmd *cobra.Command, _ []string) (err error) { current := getCurrentJenkins() - if current.Description != "" { - cmd.Printf("Current Jenkins's name is %s, url is %s, description is %s\n", current.Name, current.URL, current.Description) + if current == nil { + err = fmt.Errorf("no config file found or no current setting") } else { - cmd.Printf("Current Jenkins's name is %s, url is %s\n", current.Name, current.URL) + if current.Description != "" { + cmd.Printf("Current Jenkins's name is %s, url is %s, description is %s\n", current.Name, current.URL, current.Description) + } else { + cmd.Printf("Current Jenkins's name is %s, url is %s\n", current.Name, current.URL) + } } + return }, Example: ` jcli config generate jcli config list @@ -175,7 +180,9 @@ func loadConfig(path string) (err error) { // getMirrors returns the mirror list, one official mirror should be returned if user don't give it func getMirrors() (mirrors []JenkinsMirror) { - mirrors = config.Mirrors + if config != nil { + mirrors = config.Mirrors + } if len(mirrors) == 0 { mirrors = []JenkinsMirror{ { diff --git a/app/cmd/plugin_open.go b/app/cmd/plugin_open.go index 25d6de5b742ad17ad1fcbcc8181a1d7f75782623..9beaba144e1e59bd1578c203365c9bdc062d3f3b 100644 --- a/app/cmd/plugin_open.go +++ b/app/cmd/plugin_open.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "github.com/jenkins-zh/jenkins-cli/util" "github.com/spf13/cobra" )