mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
always add but hide experimental cmds and flags
Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
parent
c072347078
commit
3e43fa28ec
5 changed files with 47 additions and 19 deletions
|
@ -45,7 +45,7 @@ type DockerCli struct {
|
|||
func (cli *DockerCli) HasExperimental() bool {
|
||||
if cli.hasExperimental == nil {
|
||||
if cli.client == nil {
|
||||
cli.Initialize(cliflags.NewClientOptions())
|
||||
return false
|
||||
}
|
||||
enabled := false
|
||||
cli.hasExperimental = &enabled
|
||||
|
|
|
@ -70,17 +70,12 @@ func AddCommands(cmd *cobra.Command, dockerCli *command.DockerCli) {
|
|||
hide(image.NewSaveCommand(dockerCli)),
|
||||
hide(image.NewTagCommand(dockerCli)),
|
||||
hide(system.NewInspectCommand(dockerCli)),
|
||||
stack.NewStackCommand(dockerCli),
|
||||
stack.NewTopLevelDeployCommand(dockerCli),
|
||||
checkpoint.NewCheckpointCommand(dockerCli),
|
||||
plugin.NewPluginCommand(dockerCli),
|
||||
)
|
||||
|
||||
if dockerCli.HasExperimental() {
|
||||
cmd.AddCommand(
|
||||
stack.NewStackCommand(dockerCli),
|
||||
stack.NewTopLevelDeployCommand(dockerCli),
|
||||
checkpoint.NewCheckpointCommand(dockerCli),
|
||||
plugin.NewPluginCommand(dockerCli),
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func hide(cmd *cobra.Command) *cobra.Command {
|
||||
|
|
|
@ -45,11 +45,10 @@ func NewStartCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|||
flags.BoolVarP(&opts.openStdin, "interactive", "i", false, "Attach container's STDIN")
|
||||
flags.StringVar(&opts.detachKeys, "detach-keys", "", "Override the key sequence for detaching a container")
|
||||
|
||||
if dockerCli.HasExperimental() {
|
||||
flags.StringVar(&opts.checkpoint, "checkpoint", "", "Restore from this checkpoint")
|
||||
flags.StringVar(&opts.checkpointDir, "checkpoint-dir", "", "Use a custom checkpoint storage directory")
|
||||
}
|
||||
|
||||
flags.StringVar(&opts.checkpoint, "checkpoint", "", "Restore from this checkpoint")
|
||||
flags.StringVar(&opts.checkpointDir, "checkpoint-dir", "", "Use a custom checkpoint storage directory")
|
||||
flags.SetAnnotation("checkpoint", "experimental", nil)
|
||||
flags.SetAnnotation("checkpoint-dir", "experimental", nil)
|
||||
return cmd
|
||||
}
|
||||
|
||||
|
|
|
@ -111,9 +111,8 @@ func NewBuildCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|||
|
||||
command.AddTrustedFlags(flags, true)
|
||||
|
||||
if dockerCli.HasExperimental() {
|
||||
flags.BoolVar(&options.squash, "squash", false, "Squash newly built layers into a single new layer")
|
||||
}
|
||||
flags.BoolVar(&options.squash, "squash", false, "Squash newly built layers into a single new layer")
|
||||
flags.SetAnnotation("squash", "experimental", nil)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/cli"
|
||||
|
@ -33,7 +34,8 @@ func newDockerCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|||
showVersion()
|
||||
return nil
|
||||
}
|
||||
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString())
|
||||
cmd.SetOutput(dockerCli.Err())
|
||||
cmd.HelpFunc()(cmd, args)
|
||||
return nil
|
||||
},
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
@ -45,6 +47,22 @@ func newDockerCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|||
}
|
||||
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.BoolVarP(&opts.Version, "version", "v", false, "Print version information and quit")
|
||||
flags.StringVar(&opts.ConfigDir, "config", cliconfig.ConfigDir(), "Location of client config files")
|
||||
|
@ -105,3 +123,20 @@ func dockerPreRun(opts *cliflags.ClientOptions) {
|
|||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue