version.go
version.go - Overview
This file defines the version
command for the DiceDB CLI, which prints the current DiceDB version to the console.
Detailed Documentation
versionCmd
var versionCmd = &cobra.Command{
Use: "version",
Short: "print the version of DiceDB",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(config.DiceDBVersion)
},
}
- Purpose: Defines the
version
command using thecobra
library. When executed, this command prints the DiceDB version to standard output.Use
: The command's name, "version".Short
: A brief description of the command: "print the version of DiceDB".Run
: The function to execute when the command is invoked. It prints the value ofconfig.DiceDBVersion
to the console.
- Parameters:
cmd
(*cobra.Command): The cobra command object.args
([]string): Command line arguments passed to the command.
- Returns: None
init()
func init() {
rootCmd.AddCommand(versionCmd)
}
- Purpose: This function is automatically executed when the
cmd
package is initialized. It adds theversionCmd
to therootCmd
, making it available as a subcommand. - Parameters: None
- Returns: None