From 249d4e5709da7e1438e9eeab1190fb9f097b4058 Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Wed, 30 Nov 2016 13:23:18 -0800 Subject: [PATCH] Show usage when `docker swarm update` has no flags This fix tries to address the issue raised in 24352. Previously, when `docker swarm update` has no flags, the output is ``` Swarm updated. ``` even though nothing was updated. This could be misleading for users. This fix tries to address the issue by adding a `PreRunE` function in the command so that in case no flag is provided (`cmd.Flags().NFlag() == 0`), the usage will be outputed instead. An integration has been added to cover the changes. This fix fixes 24352. Signed-off-by: Yong Tang --- command/swarm/update.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/command/swarm/update.go b/command/swarm/update.go index cb0d83ef26..dbbd268725 100644 --- a/command/swarm/update.go +++ b/command/swarm/update.go @@ -23,6 +23,12 @@ func newUpdateCommand(dockerCli *command.DockerCli) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { return runUpdate(dockerCli, cmd.Flags(), opts) }, + PreRunE: func(cmd *cobra.Command, args []string) error { + if cmd.Flags().NFlag() == 0 { + return pflag.ErrHelp + } + return nil + }, } cmd.Flags().BoolVar(&opts.autolock, flagAutolock, false, "Change manager autolocking setting (true|false)")