/
center_identity.go
44 lines (37 loc) · 1.05 KB
/
center_identity.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 (
"encoding/json"
"github.com/jenkins-zh/jenkins-cli/app/cmd/common"
"github.com/jenkins-zh/jenkins-cli/app/i18n"
"github.com/jenkins-zh/jenkins-cli/client"
"github.com/spf13/cobra"
)
// CenterIdentityOption option for upgrade Jenkins
type CenterIdentityOption struct {
common.Option
}
var centerIdentityOption CenterIdentityOption
func init() {
centerCmd.AddCommand(centerIdentityCmd)
}
var centerIdentityCmd = &cobra.Command{
Use: "identity",
Short: i18n.T("Print the identity of current Jenkins"),
Long: i18n.T("Print the identity of current Jenkins"),
RunE: func(cmd *cobra.Command, _ []string) (err error) {
jClient := &client.CoreClient{
JenkinsCore: client.JenkinsCore{
RoundTripper: centerIdentityOption.RoundTripper,
},
}
getCurrentJenkinsAndClient(&(jClient.JenkinsCore))
var identity client.JenkinsIdentity
var data []byte
if identity, err = jClient.GetIdentity(); err == nil {
if data, err = json.MarshalIndent(identity, "", " "); err == nil {
cmd.Println(string(data))
}
}
return
},
}