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

--installer-context option is experimental #733

Merged
merged 1 commit into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"}) //nolint:errcheck
}

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