Use Cobra built-in --version feature
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
9411856536
commit
0c3192da8c
3 changed files with 3 additions and 10 deletions
|
@ -22,6 +22,7 @@ func SetupRootCommand(rootCmd *cobra.Command) {
|
|||
rootCmd.SetHelpTemplate(helpTemplate)
|
||||
rootCmd.SetFlagErrorFunc(FlagErrorFunc)
|
||||
rootCmd.SetHelpCommand(helpCommand)
|
||||
rootCmd.SetVersionTemplate("Docker version {{.Version}}\n")
|
||||
|
||||
rootCmd.PersistentFlags().BoolP("help", "h", false, "Print usage")
|
||||
rootCmd.PersistentFlags().MarkShorthandDeprecated("help", "please use --help")
|
||||
|
|
|
@ -24,19 +24,16 @@ func newDaemonCommand() *cobra.Command {
|
|||
SilenceErrors: true,
|
||||
Args: cli.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if opts.version {
|
||||
showVersion()
|
||||
return nil
|
||||
}
|
||||
opts.flags = cmd.Flags()
|
||||
return runDaemon(opts)
|
||||
},
|
||||
DisableFlagsInUseLine: true,
|
||||
Version: fmt.Sprintf("%s, build %s", dockerversion.Version, dockerversion.GitCommit),
|
||||
}
|
||||
cli.SetupRootCommand(cmd)
|
||||
|
||||
flags := cmd.Flags()
|
||||
flags.BoolVarP(&opts.version, "version", "v", false, "Print version information and quit")
|
||||
flags.BoolP("version", "v", false, "Print version information and quit")
|
||||
flags.StringVar(&opts.configFile, "config-file", defaultDaemonConfigFile, "Daemon configuration file")
|
||||
opts.InstallFlags(flags)
|
||||
installConfigFlags(opts.daemonConfig, flags)
|
||||
|
@ -45,10 +42,6 @@ func newDaemonCommand() *cobra.Command {
|
|||
return cmd
|
||||
}
|
||||
|
||||
func showVersion() {
|
||||
fmt.Printf("Docker version %s, build %s\n", dockerversion.Version, dockerversion.GitCommit)
|
||||
}
|
||||
|
||||
func main() {
|
||||
if reexec.Init() {
|
||||
return
|
||||
|
|
|
@ -30,7 +30,6 @@ var (
|
|||
)
|
||||
|
||||
type daemonOptions struct {
|
||||
version bool
|
||||
configFile string
|
||||
daemonConfig *config.Config
|
||||
flags *pflag.FlagSet
|
||||
|
|
Loading…
Reference in a new issue