-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
user_delete.go
51 lines (42 loc) · 1.26 KB
/
user_delete.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
45
46
47
48
49
50
51
package cmd
import (
"fmt"
"github.com/jenkins-zh/jenkins-cli/app/cmd/common"
"github.com/jenkins-zh/jenkins-cli/app/i18n"
"net/http"
"github.com/jenkins-zh/jenkins-cli/client"
"github.com/spf13/cobra"
)
// UserDeleteOption is user delete cmd option
type UserDeleteOption struct {
common.BatchOption
RoundTripper http.RoundTripper
}
var userDeleteOption UserDeleteOption
func init() {
userCmd.AddCommand(userDeleteCmd)
userDeleteCmd.Flags().BoolVarP(&userDeleteOption.Batch, "batch", "b", false,
i18n.T("Batch mode, no need confirm"))
userDeleteOption.BatchOption.Stdio = common.GetSystemStdio()
}
var userDeleteCmd = &cobra.Command{
Use: "delete <username>",
Aliases: common.GetAliasesDel(),
Short: "Delete a user for your Jenkins",
Long: `Delete a user for your Jenkins`,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
username := args[0]
if !userDeleteOption.Confirm(fmt.Sprintf("Are you sure to delete user %s ?", username)) {
return
}
jclient := &client.UserClient{
JenkinsCore: client.JenkinsCore{
RoundTripper: userDeleteOption.RoundTripper,
Debug: rootOptions.Debug,
},
}
getCurrentJenkinsAndClientOrDie(&(jclient.JenkinsCore))
return jclient.Delete(username)
},
}