From d926e7b4ca35ceeb00c609654a1324f32dff6f34 Mon Sep 17 00:00:00 2001 From: Yanjun Shi <20575981+yJunS@users.noreply.github.com> Date: Wed, 14 Aug 2019 22:26:30 +0800 Subject: [PATCH] fix remove a config (#102) * fix remove a config * update remove current Jenkins config * update error information * update some information --- app/cmd/config.go | 4 ++-- app/cmd/config_remove.go | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/cmd/config.go b/app/cmd/config.go index 040670b..a4c9c1a 100644 --- a/app/cmd/config.go +++ b/app/cmd/config.go @@ -69,9 +69,9 @@ func setCurrentJenkins(name string) { } } -var config Config +var config *Config -func getConfig() Config { +func getConfig() *Config { return config } diff --git a/app/cmd/config_remove.go b/app/cmd/config_remove.go index e3f5056..a51ee33 100644 --- a/app/cmd/config_remove.go +++ b/app/cmd/config_remove.go @@ -30,7 +30,8 @@ var configRemoveCmd = &cobra.Command{ func removeJenkins(name string) (err error) { current := getCurrentJenkins() if name == current.Name { - err = fmt.Errorf("You cannot remove current Jenkins") + err = fmt.Errorf("You cannot remove current Jenkins, if you want to remove it, can select other items before") + return } index := -1 @@ -45,10 +46,7 @@ func removeJenkins(name string) (err error) { if index == -1 { err = fmt.Errorf("Cannot found by name %s", name) } else { - config.JenkinsServers[index] = config.JenkinsServers[len(config.JenkinsServers)-1] - config.JenkinsServers[len(config.JenkinsServers)-1] = JenkinsServer{} - config.JenkinsServers = config.JenkinsServers[:len(config.JenkinsServers)-1] - + config.JenkinsServers = append(config.JenkinsServers[:index], config.JenkinsServers[index+1:]...) err = saveConfig() } return -- GitLab