diff --git a/cmds/version.go b/cmds/version.go new file mode 100644 index 0000000..3e21e33 --- /dev/null +++ b/cmds/version.go @@ -0,0 +1,22 @@ +package cmds + +import ( + "fmt" + + "github.com/alphauslabs/bluectl/params" + "github.com/spf13/cobra" +) + +func VersionCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "version", + Short: "Get current version", + Long: `Get current version.`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("bluectl", params.Version) + }, + } + + cmd.Flags().SortFlags = false + return cmd +} diff --git a/main.go b/main.go index ca42cf9..250e3f2 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,10 @@ import ( ) var ( + version = "dev" + commit = "none" + date = "unknown" + bold = color.New(color.Bold).SprintFunc() year = func() string { return fmt.Sprintf("%v", time.Now().Year()) @@ -34,6 +38,7 @@ the ` + bold("--raw-input") + ` flag to be always in sync with the current featu built-in flags don't support all the possible input combinations yet. For beta APIs, we recommend you to use the ` + bold("--raw-input") + ` flag. See https://labs.alphaus.cloud/blueapidocs/ for the latest API reference.`, PersistentPreRun: func(cmd *cobra.Command, args []string) { + params.Version = version if params.CleanOut { logger.SetPrefix(logger.PrefixNone) } @@ -108,6 +113,7 @@ func init() { cmds.BillingCmd(), cmds.NotificationCmd(), cmds.OpsCmd(), + cmds.VersionCmd(), ) } diff --git a/params/params.go b/params/params.go index 66bf865..0daa6ce 100644 --- a/params/params.go +++ b/params/params.go @@ -1,6 +1,8 @@ package params var ( + Version string + AuthProfile string AuthUrl string ClientId string