1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #28561 from vieux/poc_cmd_error_unsuported

error on cli when trying to use experimental feature with non experimental daemon
This commit is contained in:
Victor Vieux 2016-11-18 18:47:36 -08:00 committed by GitHub
commit 0337822d34

View file

@ -1,6 +1,7 @@
package main package main
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
@ -44,19 +45,27 @@ func newDockerCommand(dockerCli *command.DockerCli) *cobra.Command {
// flags must be the top-level command flags, not cmd.Flags() // flags must be the top-level command flags, not cmd.Flags()
opts.Common.SetDefaultOptions(flags) opts.Common.SetDefaultOptions(flags)
dockerPreRun(opts) dockerPreRun(opts)
return dockerCli.Initialize(opts) if err := dockerCli.Initialize(opts); err != nil {
return err
}
return isSupported(cmd, dockerCli.Client().ClientVersion(), dockerCli.HasExperimental())
}, },
} }
cli.SetupRootCommand(cmd) cli.SetupRootCommand(cmd)
cmd.SetHelpFunc(func(ccmd *cobra.Command, args []string) { cmd.SetHelpFunc(func(ccmd *cobra.Command, args []string) {
if dockerCli.Client() == nil { if dockerCli.Client() == nil { // when using --help, PersistenPreRun is not called, so initialization is needed.
// flags must be the top-level command flags, not cmd.Flags() // flags must be the top-level command flags, not cmd.Flags()
opts.Common.SetDefaultOptions(flags) opts.Common.SetDefaultOptions(flags)
dockerPreRun(opts) dockerPreRun(opts)
dockerCli.Initialize(opts) dockerCli.Initialize(opts)
} }
if err := isSupported(ccmd, dockerCli.Client().ClientVersion(), dockerCli.HasExperimental()); err != nil {
ccmd.Println(err)
return
}
hideUnsupportedFeatures(ccmd, dockerCli.Client().ClientVersion(), dockerCli.HasExperimental()) hideUnsupportedFeatures(ccmd, dockerCli.Client().ClientVersion(), dockerCli.HasExperimental())
if err := ccmd.Help(); err != nil { if err := ccmd.Help(); err != nil {
@ -155,3 +164,17 @@ func hideUnsupportedFeatures(cmd *cobra.Command, clientVersion string, hasExperi
} }
} }
} }
func isSupported(cmd *cobra.Command, clientVersion string, hasExperimental bool) error {
if !hasExperimental {
if _, ok := cmd.Tags["experimental"]; ok {
return errors.New("only supported with experimental daemon")
}
}
if cmdVersion, ok := cmd.Tags["version"]; ok && versions.LessThan(clientVersion, cmdVersion) {
return fmt.Errorf("only supported with daemon version >= %s", cmdVersion)
}
return nil
}