From 5dac31cb102af32dbe3f05e0f415ebf1de18ba8d Mon Sep 17 00:00:00 2001 From: Yanjun Shi <20575981+yJunS@users.noreply.github.com> Date: Thu, 15 Aug 2019 10:50:04 +0800 Subject: [PATCH] Add support to add description for the jcli config item (#101) * Add support to add description for the jcli config item * fix error * delete useless information --- app/cmd/config.go | 19 ++++++++++++------- app/cmd/config_add.go | 1 + app/cmd/config_list.go | 8 ++++++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/cmd/config.go b/app/cmd/config.go index a4c9c1a..5d37a59 100644 --- a/app/cmd/config.go +++ b/app/cmd/config.go @@ -28,7 +28,11 @@ var configCmd = &cobra.Command{ Long: `Manage the config of jcli`, Run: func(cmd *cobra.Command, args []string) { current := getCurrentJenkins() - fmt.Printf("Current Jenkins's name is %s, url is %s\n", current.Name, current.URL) + if current.Description != "" { + fmt.Printf("Current Jenkins's name is %s, url is %s, description is %s\n", current.Name, current.URL, current.Description) + } else { + fmt.Printf("Current Jenkins's name is %s, url is %s\n", current.Name, current.URL) + } }, Example: ` jcli config generate jcli config list @@ -37,12 +41,13 @@ var configCmd = &cobra.Command{ // JenkinsServer holds the configuration of your Jenkins type JenkinsServer struct { - Name string `yaml:"name"` - URL string `yaml:"url"` - UserName string `yaml:"username"` - Token string `yaml:"token"` - Proxy string `yaml:"proxy"` - ProxyAuth string `yaml:"proxyAuth"` + Name string `yaml:"name"` + URL string `yaml:"url"` + UserName string `yaml:"username"` + Token string `yaml:"token"` + Proxy string `yaml:"proxy"` + ProxyAuth string `yaml:"proxyAuth"` + Description string `yaml:"description"` } type Config struct { diff --git a/app/cmd/config_add.go b/app/cmd/config_add.go index 1e6e6fa..d3cf54a 100644 --- a/app/cmd/config_add.go +++ b/app/cmd/config_add.go @@ -21,6 +21,7 @@ func init() { configAddCmd.Flags().StringVarP(&configAddOptions.Token, "token", "t", "", "Token of the Jenkins") configAddCmd.Flags().StringVarP(&configAddOptions.Proxy, "proxy", "p", "", "Proxy of the Jenkins") configAddCmd.Flags().StringVarP(&configAddOptions.ProxyAuth, "proxyAuth", "a", "", "ProxyAuth of the Jenkins") + configAddCmd.Flags().StringVarP(&configAddOptions.Description, "description", "d", "", "Description of the Jenkins") } var configAddCmd = &cobra.Command{ diff --git a/app/cmd/config_list.go b/app/cmd/config_list.go index 9c0fcc4..388a10c 100644 --- a/app/cmd/config_list.go +++ b/app/cmd/config_list.go @@ -20,13 +20,17 @@ var configListCmd = &cobra.Command{ current := getCurrentJenkins() table := util.CreateTable(os.Stdout) - table.AddRow("number", "name", "url") + table.AddRow("number", "name", "url", "description") for i, jenkins := range getConfig().JenkinsServers { name := jenkins.Name if name == current.Name { name = fmt.Sprintf("*%s", name) } - table.AddRow(fmt.Sprintf("%d", i), name, jenkins.URL) + if len(jenkins.Description) > 15 { + table.AddRow(fmt.Sprintf("%d", i), name, jenkins.URL, jenkins.Description[0:15]) + } else { + table.AddRow(fmt.Sprintf("%d", i), name, jenkins.URL, jenkins.Description) + } } table.Render() }, -- GitLab