Signed-off-by: Victor Vieux <vieux@docker.com>
| ... | ... |
@@ -45,7 +45,7 @@ type DockerCli struct {
|
| 45 | 45 |
func (cli *DockerCli) HasExperimental() bool {
|
| 46 | 46 |
if cli.hasExperimental == nil {
|
| 47 | 47 |
if cli.client == nil {
|
| 48 |
- cli.Initialize(cliflags.NewClientOptions()) |
|
| 48 |
+ return false |
|
| 49 | 49 |
} |
| 50 | 50 |
enabled := false |
| 51 | 51 |
cli.hasExperimental = &enabled |
| ... | ... |
@@ -70,17 +70,12 @@ func AddCommands(cmd *cobra.Command, dockerCli *command.DockerCli) {
|
| 70 | 70 |
hide(image.NewSaveCommand(dockerCli)), |
| 71 | 71 |
hide(image.NewTagCommand(dockerCli)), |
| 72 | 72 |
hide(system.NewInspectCommand(dockerCli)), |
| 73 |
+ stack.NewStackCommand(dockerCli), |
|
| 74 |
+ stack.NewTopLevelDeployCommand(dockerCli), |
|
| 75 |
+ checkpoint.NewCheckpointCommand(dockerCli), |
|
| 76 |
+ plugin.NewPluginCommand(dockerCli), |
|
| 73 | 77 |
) |
| 74 | 78 |
|
| 75 |
- if dockerCli.HasExperimental() {
|
|
| 76 |
- cmd.AddCommand( |
|
| 77 |
- stack.NewStackCommand(dockerCli), |
|
| 78 |
- stack.NewTopLevelDeployCommand(dockerCli), |
|
| 79 |
- checkpoint.NewCheckpointCommand(dockerCli), |
|
| 80 |
- plugin.NewPluginCommand(dockerCli), |
|
| 81 |
- ) |
|
| 82 |
- } |
|
| 83 |
- |
|
| 84 | 79 |
} |
| 85 | 80 |
|
| 86 | 81 |
func hide(cmd *cobra.Command) *cobra.Command {
|
| ... | ... |
@@ -45,11 +45,10 @@ func NewStartCommand(dockerCli *command.DockerCli) *cobra.Command {
|
| 45 | 45 |
flags.BoolVarP(&opts.openStdin, "interactive", "i", false, "Attach container's STDIN") |
| 46 | 46 |
flags.StringVar(&opts.detachKeys, "detach-keys", "", "Override the key sequence for detaching a container") |
| 47 | 47 |
|
| 48 |
- if dockerCli.HasExperimental() {
|
|
| 49 |
- flags.StringVar(&opts.checkpoint, "checkpoint", "", "Restore from this checkpoint") |
|
| 50 |
- flags.StringVar(&opts.checkpointDir, "checkpoint-dir", "", "Use a custom checkpoint storage directory") |
|
| 51 |
- } |
|
| 52 |
- |
|
| 48 |
+ flags.StringVar(&opts.checkpoint, "checkpoint", "", "Restore from this checkpoint") |
|
| 49 |
+ flags.StringVar(&opts.checkpointDir, "checkpoint-dir", "", "Use a custom checkpoint storage directory") |
|
| 50 |
+ flags.SetAnnotation("checkpoint", "experimental", nil)
|
|
| 51 |
+ flags.SetAnnotation("checkpoint-dir", "experimental", nil)
|
|
| 53 | 52 |
return cmd |
| 54 | 53 |
} |
| 55 | 54 |
|
| ... | ... |
@@ -111,9 +111,8 @@ func NewBuildCommand(dockerCli *command.DockerCli) *cobra.Command {
|
| 111 | 111 |
|
| 112 | 112 |
command.AddTrustedFlags(flags, true) |
| 113 | 113 |
|
| 114 |
- if dockerCli.HasExperimental() {
|
|
| 115 |
- flags.BoolVar(&options.squash, "squash", false, "Squash newly built layers into a single new layer") |
|
| 116 |
- } |
|
| 114 |
+ flags.BoolVar(&options.squash, "squash", false, "Squash newly built layers into a single new layer") |
|
| 115 |
+ flags.SetAnnotation("squash", "experimental", nil)
|
|
| 117 | 116 |
|
| 118 | 117 |
return cmd |
| 119 | 118 |
} |
| ... | ... |
@@ -3,6 +3,7 @@ package main |
| 3 | 3 |
import ( |
| 4 | 4 |
"fmt" |
| 5 | 5 |
"os" |
| 6 |
+ "strings" |
|
| 6 | 7 |
|
| 7 | 8 |
"github.com/Sirupsen/logrus" |
| 8 | 9 |
"github.com/docker/docker/cli" |
| ... | ... |
@@ -33,7 +34,8 @@ func newDockerCommand(dockerCli *command.DockerCli) *cobra.Command {
|
| 33 | 33 |
showVersion() |
| 34 | 34 |
return nil |
| 35 | 35 |
} |
| 36 |
- fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) |
|
| 36 |
+ cmd.SetOutput(dockerCli.Err()) |
|
| 37 |
+ cmd.HelpFunc()(cmd, args) |
|
| 37 | 38 |
return nil |
| 38 | 39 |
}, |
| 39 | 40 |
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
| ... | ... |
@@ -45,6 +47,22 @@ func newDockerCommand(dockerCli *command.DockerCli) *cobra.Command {
|
| 45 | 45 |
} |
| 46 | 46 |
cli.SetupRootCommand(cmd) |
| 47 | 47 |
|
| 48 |
+ cmd.SetHelpFunc(func(ccmd *cobra.Command, args []string) {
|
|
| 49 |
+ var err error |
|
| 50 |
+ if dockerCli.Client() == nil {
|
|
| 51 |
+ // flags must be the top-level command flags, not cmd.Flags() |
|
| 52 |
+ opts.Common.SetDefaultOptions(flags) |
|
| 53 |
+ dockerPreRun(opts) |
|
| 54 |
+ err = dockerCli.Initialize(opts) |
|
| 55 |
+ } |
|
| 56 |
+ if err != nil || !dockerCli.HasExperimental() {
|
|
| 57 |
+ hideExperimentalFeatures(ccmd) |
|
| 58 |
+ } |
|
| 59 |
+ if err := ccmd.Help(); err != nil {
|
|
| 60 |
+ ccmd.Println(err) |
|
| 61 |
+ } |
|
| 62 |
+ }) |
|
| 63 |
+ |
|
| 48 | 64 |
flags = cmd.Flags() |
| 49 | 65 |
flags.BoolVarP(&opts.Version, "version", "v", false, "Print version information and quit") |
| 50 | 66 |
flags.StringVar(&opts.ConfigDir, "config", cliconfig.ConfigDir(), "Location of client config files") |
| ... | ... |
@@ -105,3 +123,20 @@ func dockerPreRun(opts *cliflags.ClientOptions) {
|
| 105 | 105 |
utils.EnableDebug() |
| 106 | 106 |
} |
| 107 | 107 |
} |
| 108 |
+ |
|
| 109 |
+func hideExperimentalFeatures(cmd *cobra.Command) {
|
|
| 110 |
+ // hide flags |
|
| 111 |
+ cmd.Flags().VisitAll(func(f *pflag.Flag) {
|
|
| 112 |
+ if _, ok := f.Annotations["experimental"]; ok {
|
|
| 113 |
+ f.Hidden = true |
|
| 114 |
+ } |
|
| 115 |
+ }) |
|
| 116 |
+ |
|
| 117 |
+ for _, subcmd := range cmd.Commands() {
|
|
| 118 |
+ // hide subcommands |
|
| 119 |
+ name := strings.Split(subcmd.Use, " ")[0] |
|
| 120 |
+ if name == "stack" || name == "deploy" || name == "checkpoint" || name == "plugin" {
|
|
| 121 |
+ subcmd.Hidden = true |
|
| 122 |
+ } |
|
| 123 |
+ } |
|
| 124 |
+} |