mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
error on cli when trying to use experimental feature with non experimental daemon
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
(cherry picked from commit 98bb08fe38
)
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
This commit is contained in:
parent
fe8e347741
commit
e773e0e654
1 changed files with 25 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
|
@ -44,19 +45,27 @@ func newDockerCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|||
// flags must be the top-level command flags, not cmd.Flags()
|
||||
opts.Common.SetDefaultOptions(flags)
|
||||
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)
|
||||
|
||||
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()
|
||||
opts.Common.SetDefaultOptions(flags)
|
||||
dockerPreRun(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())
|
||||
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue