diff --git a/internal/base/base.go b/internal/base/base.go index f559589..2159e22 100644 --- a/internal/base/base.go +++ b/internal/base/base.go @@ -17,6 +17,9 @@ import ( "github.com/rs/xid" ) +// Version of asynq library and CLI. +const Version = "0.10.0" + // DefaultQueueName is the queue name used if none are specified by user. const DefaultQueueName = "default" diff --git a/tools/asynq/cmd/migrate.go b/tools/asynq/cmd/migrate.go index cf883cf..a0fe238 100644 --- a/tools/asynq/cmd/migrate.go +++ b/tools/asynq/cmd/migrate.go @@ -19,13 +19,11 @@ import ( "github.com/spf13/viper" ) -const version = "v0.10.0" // TODO: Define this version string in a more canonical place. - // migrateCmd represents the migrate command var migrateCmd = &cobra.Command{ Use: "migrate", - Short: fmt.Sprintf("Migrate all tasks to be compatible with asynq@%s", version), - Long: fmt.Sprintf("Migrate (asynq migrate) will convert all tasks in redis to be compatible with asynq@%s.", version), + Short: fmt.Sprintf("Migrate all tasks to be compatible with asynq@%s", base.Version), + Long: fmt.Sprintf("Migrate (asynq migrate) will convert all tasks in redis to be compatible with asynq@%s.", base.Version), Run: migrate, } diff --git a/tools/asynq/cmd/root.go b/tools/asynq/cmd/root.go index 8056ac5..12ceaa4 100644 --- a/tools/asynq/cmd/root.go +++ b/tools/asynq/cmd/root.go @@ -11,6 +11,7 @@ import ( "strings" "text/tabwriter" + "github.com/hibiken/asynq/internal/base" "github.com/spf13/cobra" homedir "github.com/mitchellh/go-homedir" @@ -26,9 +27,20 @@ var password string // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ - Use: "asynq", - Short: "A monitoring tool for asynq queues", - Long: `Asynq is a montoring CLI to inspect tasks and queues managed by asynq.`, + Use: "asynq", + Short: "A monitoring tool for asynq queues", + Long: `Asynq is a montoring CLI to inspect tasks and queues managed by asynq.`, + Version: base.Version, +} + +var versionOutput = fmt.Sprintf("asynq version %s\n", base.Version) + +var versionCmd = &cobra.Command{ + Use: "version", + Hidden: true, + Run: func(cmd *cobra.Command, args []string) { + fmt.Print(versionOutput) + }, } // Execute adds all child commands to the root command and sets flags appropriately. @@ -43,6 +55,9 @@ func Execute() { func init() { cobra.OnInitialize(initConfig) + rootCmd.AddCommand(versionCmd) + rootCmd.SetVersionTemplate(versionOutput) + rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file to set flag defaut values (default is $HOME/.asynq.yaml)") rootCmd.PersistentFlags().StringVarP(&uri, "uri", "u", "127.0.0.1:6379", "redis server URI") rootCmd.PersistentFlags().IntVarP(&db, "db", "n", 0, "redis database number (default is 0)")