Using builtin cobra version function.
This commit is contained in:
parent
50ec7cad2c
commit
e4554309f4
1 changed files with 13 additions and 22 deletions
35
cmd/root.go
35
cmd/root.go
|
@ -9,17 +9,6 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
|
||||||
Use: "australis",
|
|
||||||
Short: "australis is a client for Apache Aurora",
|
|
||||||
Long: `A light-weight command line client for use with Apache Aurora built using gorealis.`,
|
|
||||||
PersistentPreRun: connect,
|
|
||||||
PersistentPostRun: func(cmd *cobra.Command, args []string) {
|
|
||||||
// Make all children close the client by default upon terminating
|
|
||||||
client.Close()
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
var username, password, zkAddr, schedAddr string
|
var username, password, zkAddr, schedAddr string
|
||||||
var env, role, name = new(string), new(string), new(string)
|
var env, role, name = new(string), new(string), new(string)
|
||||||
var client realis.Realis
|
var client realis.Realis
|
||||||
|
@ -33,6 +22,8 @@ const australisVer = "v0.0.5"
|
||||||
var monitorInterval, monitorTimeout int
|
var monitorInterval, monitorTimeout int
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
rootCmd.SetVersionTemplate(`{{printf "%s\n" .Version}}`)
|
||||||
|
|
||||||
rootCmd.PersistentFlags().StringVarP(&zkAddr, "zookeeper", "z", "", "Zookeeper node(s) where Aurora stores information.")
|
rootCmd.PersistentFlags().StringVarP(&zkAddr, "zookeeper", "z", "", "Zookeeper node(s) where Aurora stores information.")
|
||||||
rootCmd.PersistentFlags().StringVarP(&username, "username", "u", "", "Username to use for API authentication")
|
rootCmd.PersistentFlags().StringVarP(&username, "username", "u", "", "Username to use for API authentication")
|
||||||
rootCmd.PersistentFlags().StringVarP(&password, "password", "p", "", "Password to use for API authentication")
|
rootCmd.PersistentFlags().StringVarP(&password, "password", "p", "", "Password to use for API authentication")
|
||||||
|
@ -41,24 +32,24 @@ func init() {
|
||||||
rootCmd.PersistentFlags().StringVarP(&clientCert, "clientCert", "c", "", "Client certificate to use to connect to Aurora.")
|
rootCmd.PersistentFlags().StringVarP(&clientCert, "clientCert", "c", "", "Client certificate to use to connect to Aurora.")
|
||||||
rootCmd.PersistentFlags().StringVarP(&caCertsPath, "caCertsPath", "a", "", "CA certificates path to use.")
|
rootCmd.PersistentFlags().StringVarP(&caCertsPath, "caCertsPath", "a", "", "CA certificates path to use.")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&insecureSkipVerify, "insecureSkipVerify", "i", false, "Skip verification.")
|
rootCmd.PersistentFlags().BoolVarP(&insecureSkipVerify, "insecureSkipVerify", "i", false, "Skip verification.")
|
||||||
|
}
|
||||||
|
|
||||||
|
var rootCmd = &cobra.Command{
|
||||||
// Add version command
|
Use: "australis",
|
||||||
rootCmd.AddCommand(versionCmd)
|
Short: "australis is a client for Apache Aurora",
|
||||||
|
Long: `A light-weight command line client for use with Apache Aurora built using gorealis.`,
|
||||||
|
PersistentPreRun: connect,
|
||||||
|
PersistentPostRun: func(cmd *cobra.Command, args []string) {
|
||||||
|
// Make all children close the client by default upon terminating
|
||||||
|
client.Close()
|
||||||
|
},
|
||||||
|
Version: australisVer,
|
||||||
}
|
}
|
||||||
|
|
||||||
func Execute() {
|
func Execute() {
|
||||||
rootCmd.Execute()
|
rootCmd.Execute()
|
||||||
}
|
}
|
||||||
|
|
||||||
var versionCmd = &cobra.Command{
|
|
||||||
Use: "version",
|
|
||||||
Short: "Get version",
|
|
||||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {}, //We don't need a realis client for this cmd
|
|
||||||
PersistentPostRun: func(cmd *cobra.Command, args []string) {}, //We don't need a realis client for this cmd
|
|
||||||
Run: func(cmd *cobra.Command, args []string){ fmt.Println(australisVer) },
|
|
||||||
}
|
|
||||||
|
|
||||||
func connect(cmd *cobra.Command, args []string) {
|
func connect(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue