/
del.go
44 lines (39 loc) · 846 Bytes
/
del.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package cmd
import (
"fmt"
"github.com/gocruncher/jenkins-job-ctl/cmd/jj"
"github.com/spf13/cobra"
)
func init() {
delCmd := &cobra.Command{
Use: "del NAME",
Short: "Delete a particular jenkins settings in the config file",
Run: func(cmd *cobra.Command, args []string) {
del(args)
},
}
rootCmd.AddCommand(delCmd)
}
func del(args []string) {
if len(args) == 0 {
fmt.Println("which Jenkins should be removed?")
choices := []string{}
for _, e := range jj.GetEnvs() {
choices = append(choices, string(e.Name))
}
for {
name := getAnswer("name: ", "", choices)
if err := jj.DelEnv(jj.EName(name)); err != nil {
fmt.Println(err)
continue
}
fmt.Println("Removed.")
return
}
}
if err := jj.DelEnv(jj.EName(args[0])); err != nil {
fmt.Println(err)
} else {
fmt.Println("Removed.")
}
}