forked from jenkins-zh/jenkins-cli
/
root.go
55 lines (45 loc) · 1.2 KB
/
root.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
52
53
54
55
package cmd
import (
"fmt"
"os"
"github.com/linuxsuren/jenkins-cli/app"
"github.com/spf13/cobra"
)
type RootOptions struct {
Version bool
}
var rootCmd = &cobra.Command{
Use: "jcli",
Short: "jcli is a tool which could help you with your multiple Jenkins",
Long: `jcli is Jenkins CLI which could help with your multiple Jenkins,
Manage your Jenkins and your pipelines
More information could found at https://jenkins-zh.cn`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Jenkins CLI (jcli) manage your Jenkins")
current := getCurrentJenkins()
if current != nil {
fmt.Println("Current Jenkins is:", current.Name)
} else {
fmt.Println("Cannot found the configuration")
}
if rootOptions.Version {
fmt.Printf("Version: v%.2f.%d%s", app.CurrentVersion.Number,
app.CurrentVersion.PatchLevel,
app.CurrentVersion.Suffix)
}
},
}
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
var rootOptions RootOptions
func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().BoolVarP(&rootOptions.Version, "version", "v", false, "Print the version of Jenkins CLI")
}
func initConfig() {
loadDefaultConfig()
}