root.go 1.0 KB
Newer Older
LinuxSuRen's avatar
LinuxSuRen 已提交
1 2 3 4 5 6
package cmd

import (
	"fmt"
	"os"

7
	"github.com/linuxsuren/jenkins-cli/app"
LinuxSuRen's avatar
LinuxSuRen 已提交
8 9 10
	"github.com/spf13/cobra"
)

11 12 13 14
type RootOptions struct {
	Version bool
}

LinuxSuRen's avatar
LinuxSuRen 已提交
15
var rootCmd = &cobra.Command{
16 17 18 19 20
	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`,
LinuxSuRen's avatar
LinuxSuRen 已提交
21
	Run: func(cmd *cobra.Command, args []string) {
22 23 24 25 26 27 28
		fmt.Println("Jenkins CLI (jcli) manage your Jenkins")

		if rootOptions.Version {
			fmt.Printf("Version: v%.2f.%d%s", app.CurrentVersion.Number,
				app.CurrentVersion.PatchLevel,
				app.CurrentVersion.Suffix)
		}
LinuxSuRen's avatar
LinuxSuRen 已提交
29 30 31 32 33 34 35 36 37 38
	},
}

func Execute() {
	if err := rootCmd.Execute(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}

39
var rootOptions RootOptions
LinuxSuRen's avatar
LinuxSuRen 已提交
40 41 42

func init() {
	cobra.OnInitialize(initConfig)
43
	rootCmd.PersistentFlags().BoolVarP(&rootOptions.Version, "version", "v", false, "Print the version of Jenkins CLI")
LinuxSuRen's avatar
LinuxSuRen 已提交
44 45 46
}

func initConfig() {
47
	loadDefaultConfig()
LinuxSuRen's avatar
LinuxSuRen 已提交
48
}