mirror of https://github.com/docker/cli.git
always add but hide experimental cmds and flags
Signed-off-by: Victor Vieux <vieux@docker.com> update cobra and use Tags Signed-off-by: Victor Vieux <vieux@docker.com> allow client to talk to an older server Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
parent
46418414a2
commit
e1beebbeef
27
docker.go
27
docker.go
|
@ -5,6 +5,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
|
"github.com/docker/docker/api/types/versions"
|
||||||
"github.com/docker/docker/cli"
|
"github.com/docker/docker/cli"
|
||||||
"github.com/docker/docker/cli/command"
|
"github.com/docker/docker/cli/command"
|
||||||
"github.com/docker/docker/cli/command/commands"
|
"github.com/docker/docker/cli/command/commands"
|
||||||
|
@ -47,16 +48,15 @@ func newDockerCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||||
cli.SetupRootCommand(cmd)
|
cli.SetupRootCommand(cmd)
|
||||||
|
|
||||||
cmd.SetHelpFunc(func(ccmd *cobra.Command, args []string) {
|
cmd.SetHelpFunc(func(ccmd *cobra.Command, args []string) {
|
||||||
var err error
|
|
||||||
if dockerCli.Client() == nil {
|
if dockerCli.Client() == nil {
|
||||||
// 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)
|
||||||
err = dockerCli.Initialize(opts)
|
dockerCli.Initialize(opts)
|
||||||
}
|
|
||||||
if err != nil || !dockerCli.HasExperimental() {
|
|
||||||
hideExperimentalFeatures(ccmd)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hideUnsupportedFeatures(ccmd, dockerCli.Client().ClientVersion(), dockerCli.HasExperimental())
|
||||||
|
|
||||||
if err := ccmd.Help(); err != nil {
|
if err := ccmd.Help(); err != nil {
|
||||||
ccmd.Println(err)
|
ccmd.Println(err)
|
||||||
}
|
}
|
||||||
|
@ -123,18 +123,29 @@ func dockerPreRun(opts *cliflags.ClientOptions) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func hideExperimentalFeatures(cmd *cobra.Command) {
|
func hideUnsupportedFeatures(cmd *cobra.Command, clientVersion string, hasExperimental bool) {
|
||||||
// hide flags
|
|
||||||
cmd.Flags().VisitAll(func(f *pflag.Flag) {
|
cmd.Flags().VisitAll(func(f *pflag.Flag) {
|
||||||
|
// hide experimental flags
|
||||||
if _, ok := f.Annotations["experimental"]; ok {
|
if _, ok := f.Annotations["experimental"]; ok {
|
||||||
f.Hidden = true
|
f.Hidden = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// hide flags not supported by the server
|
||||||
|
if flagVersion, ok := f.Annotations["version"]; ok && len(flagVersion) == 1 && versions.LessThan(clientVersion, flagVersion[0]) {
|
||||||
|
f.Hidden = true
|
||||||
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, subcmd := range cmd.Commands() {
|
for _, subcmd := range cmd.Commands() {
|
||||||
// hide subcommands
|
// hide experimental subcommands
|
||||||
if _, ok := subcmd.Tags["experimental"]; ok {
|
if _, ok := subcmd.Tags["experimental"]; ok {
|
||||||
subcmd.Hidden = true
|
subcmd.Hidden = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// hide subcommands not supported by the server
|
||||||
|
if subcmdVersion, ok := subcmd.Tags["version"]; ok && versions.LessThan(clientVersion, subcmdVersion) {
|
||||||
|
subcmd.Hidden = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue