|
@@ -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
|
|
|
|
+}
|