Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Commit

Permalink
--installer-context option is experimental
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Nov 12, 2019
1 parent aeb12c0 commit ca58799
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions internal/cliopts/installerContext.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func (o *InstallerContextOptions) AddFlags(flags *pflag.FlagSet) {
defaultContext = "default"
}
flags.StringVar(&o.installerContext, "installer-context", defaultContext, "Context on which the installer image is ran")
flags.SetAnnotation("installer-context", "experimentalCLI", []string{"true"})
}

func (o *InstallerContextOptions) SetInstallerContext(dockerCli command.Cli) (command.Cli, error) {
Expand Down
26 changes: 16 additions & 10 deletions internal/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewRootCmd(use string, dockerCli command.Cli) *cobra.Command {
}

func addCommands(cmd *cobra.Command, dockerCli command.Cli) {
listOfCommands := []*cobra.Command{
cmd.AddCommand(
runCmd(dockerCli),
updateCmd(dockerCli),
removeCmd(dockerCli),
Expand All @@ -60,18 +60,24 @@ func addCommands(cmd *cobra.Command, dockerCli command.Cli) {
image.Cmd(dockerCli),
build.Cmd(dockerCli),
inspectCmd(dockerCli),
)

if !dockerCli.ClientInfo().HasExperimental {
hideExperimentalCLI(cmd)
}
}

isExperimentalMode := dockerCli.ClientInfo().HasExperimental
for _, ccmd := range listOfCommands {
switch ccmd.Annotations["experimental"] {
case "true":
if isExperimentalMode {
cmd.AddCommand(ccmd)
}
default:
cmd.AddCommand(ccmd)
func hideExperimentalCLI(cmd *cobra.Command) {
if _, ok := cmd.Annotations["experimentalCLI"]; ok {
cmd.Hidden = true
}
cmd.Flags().VisitAll(func(f *pflag.Flag) {
if _, ok := f.Annotations["experimentalCLI"]; ok {
f.Hidden = true
}
})
for _, subcmd := range cmd.Commands() {
hideExperimentalCLI(subcmd)
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/commands/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func validateCmd() *cobra.Command {
Short: "Check that an App definition (.dockerapp) is syntactically correct",
Example: `$ docker app validate myapp.dockerapp --set key=value --parameters-file myparam.yml`,
Args: cli.RequiresMaxArgs(1),
Annotations: map[string]string{"experimental": "true"},
Annotations: map[string]string{"experimentalCLI": "true"},
RunE: func(cmd *cobra.Command, args []string) error {
return runValidate(args, opts)
},
Expand Down

0 comments on commit ca58799

Please sign in to comment.