always add but hide experimental cmds and flags

Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
Victor Vieux 2016-11-02 17:43:32 -07:00
parent f1b1e55f7a
commit 73d63ec5a6
1 changed files with 36 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"strings"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
@ -33,7 +34,8 @@ func newDockerCommand(dockerCli *command.DockerCli) *cobra.Command {
showVersion() showVersion()
return nil return nil
} }
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) cmd.SetOutput(dockerCli.Err())
cmd.HelpFunc()(cmd, args)
return nil return nil
}, },
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
@ -45,6 +47,22 @@ func newDockerCommand(dockerCli *command.DockerCli) *cobra.Command {
} }
cli.SetupRootCommand(cmd) cli.SetupRootCommand(cmd)
cmd.SetHelpFunc(func(ccmd *cobra.Command, args []string) {
var err error
if dockerCli.Client() == nil {
// flags must be the top-level command flags, not cmd.Flags()
opts.Common.SetDefaultOptions(flags)
dockerPreRun(opts)
err = dockerCli.Initialize(opts)
}
if err != nil || !dockerCli.HasExperimental() {
hideExperimentalFeatures(ccmd)
}
if err := ccmd.Help(); err != nil {
ccmd.Println(err)
}
})
flags = cmd.Flags() flags = cmd.Flags()
flags.BoolVarP(&opts.Version, "version", "v", false, "Print version information and quit") flags.BoolVarP(&opts.Version, "version", "v", false, "Print version information and quit")
flags.StringVar(&opts.ConfigDir, "config", cliconfig.ConfigDir(), "Location of client config files") flags.StringVar(&opts.ConfigDir, "config", cliconfig.ConfigDir(), "Location of client config files")
@ -105,3 +123,20 @@ func dockerPreRun(opts *cliflags.ClientOptions) {
utils.EnableDebug() utils.EnableDebug()
} }
} }
func hideExperimentalFeatures(cmd *cobra.Command) {
// hide flags
cmd.Flags().VisitAll(func(f *pflag.Flag) {
if _, ok := f.Annotations["experimental"]; ok {
f.Hidden = true
}
})
for _, subcmd := range cmd.Commands() {
// hide subcommands
name := strings.Split(subcmd.Use, " ")[0]
if name == "stack" || name == "deploy" || name == "checkpoint" || name == "plugin" {
subcmd.Hidden = true
}
}
}