From cc8e8442e8ef5aa3698e0083b2e0e580d386c040 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Fri, 1 Jun 2018 14:58:43 +0200 Subject: [PATCH 1/2] Added a "top-level" annotation to hide persistent flags in all sub-commands, excepting some specific commands, while printing help Fixes issue #1099 Signed-off-by: Silvin Lubecki Upstream-commit: c003ed1f35ebcfcf95079df3ed45cf9f8d14334a Component: cli --- components/cli/cmd/docker/docker.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/components/cli/cmd/docker/docker.go b/components/cli/cmd/docker/docker.go index f20530dac5..4b3c46390b 100644 --- a/components/cli/cmd/docker/docker.go +++ b/components/cli/cmd/docker/docker.go @@ -54,6 +54,7 @@ func newDockerCommand(dockerCli *command.DockerCli) *cobra.Command { // Install persistent flags persistentFlags := cmd.PersistentFlags() persistentFlags.StringVar(&opts.Common.Orchestrator, "orchestrator", "", "Orchestrator to use (swarm|kubernetes|all)") + persistentFlags.SetAnnotation("orchestrator", "top-level", []string{"version", "stack"}) setFlagErrorFunc(dockerCli, cmd, flags, opts) @@ -245,6 +246,12 @@ func hideUnsupportedFeatures(cmd *cobra.Command, details versionDetails) { if !isOSTypeSupported(f, osType) || !isVersionSupported(f, clientVersion) { f.Hidden = true } + // root command shows all top-level flags + if cmd.Parent() != nil { + if commands, ok := f.Annotations["top-level"]; ok { + f.Hidden = !findCommand(cmd, commands) + } + } }) for _, subcmd := range cmd.Commands() { @@ -259,6 +266,19 @@ func hideUnsupportedFeatures(cmd *cobra.Command, details versionDetails) { } } +// Checks if a command or one of its ancestors is in the list +func findCommand(cmd *cobra.Command, commands []string) bool { + if cmd == nil { + return false + } + for _, c := range commands { + if c == cmd.Name() { + return true + } + } + return findCommand(cmd.Parent(), commands) +} + func isSupported(cmd *cobra.Command, details versionDetails) error { if err := areSubcommandsSupported(cmd, details); err != nil { return err From a87a3769f8167ec621fb5f57a1096e576475d776 Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Fri, 1 Jun 2018 18:34:00 +0200 Subject: [PATCH 2/2] Fix panics when --compress and --stream are used together Warns that `-compress` has no effect when used together with the expremintal `--stream` flag. Signed-off-by: Vincent Demeester Upstream-commit: 8b3dc39fce3a7b92baab4f3b61c8c53bc7a06263 Component: cli --- components/cli/cli/command/image/build.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/cli/cli/command/image/build.go b/components/cli/cli/command/image/build.go index 33493f697c..4a9be0dc82 100644 --- a/components/cli/cli/command/image/build.go +++ b/components/cli/cli/command/image/build.go @@ -182,6 +182,10 @@ func runBuild(dockerCli command.Cli, options buildOptions) error { remote string ) + if options.compress && options.stream { + return errors.New("--compress conflicts with --stream options") + } + if options.dockerfileFromStdin() { if options.contextFromStdin() { return errors.New("invalid argument: can't use stdin for both build context and dockerfile")