verify that DisableFlagsInUseLine is set for all commands
This replaces the visitAll recursive function with a test that verifies that the option is set for all commands and subcommands, so that it doesn't have to be modified at runtime. We currently still have to loop over all functions for the setValidateArgs call, but that can be looked at separately. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@ -18,6 +18,8 @@ func newContextCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
Short: "Manage contexts",
|
||||
Args: cli.NoArgs,
|
||||
RunE: command.ShowHelp(dockerCLI.Err()),
|
||||
|
||||
DisableFlagsInUseLine: true,
|
||||
}
|
||||
cmd.AddCommand(
|
||||
newCreateCommand(dockerCLI),
|
||||
|
||||
@ -66,8 +66,9 @@ func newCreateCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
opts.name = args[0]
|
||||
return runCreate(dockerCLI, &opts)
|
||||
},
|
||||
Long: longCreateDescription(),
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
Long: longCreateDescription(),
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
DisableFlagsInUseLine: true,
|
||||
}
|
||||
flags := cmd.Flags()
|
||||
flags.StringVar(&opts.description, "description", "", "Description of the context")
|
||||
|
||||
@ -35,7 +35,8 @@ func newExportCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
}
|
||||
return runExport(dockerCLI, contextName, dest)
|
||||
},
|
||||
ValidArgsFunction: completeContextNames(dockerCLI, 1, true),
|
||||
ValidArgsFunction: completeContextNames(dockerCLI, 1, true),
|
||||
DisableFlagsInUseLine: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -12,16 +12,17 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func newImportCommand(dockerCli command.Cli) *cobra.Command {
|
||||
func newImportCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "import CONTEXT FILE|-",
|
||||
Short: "Import a context from a tar or zip file",
|
||||
Args: cli.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runImport(dockerCli, args[0], args[1])
|
||||
return runImport(dockerCLI, args[0], args[1])
|
||||
},
|
||||
// TODO(thaJeztah): this should also include "-"
|
||||
ValidArgsFunction: completion.FileNames,
|
||||
ValidArgsFunction: completion.FileNames,
|
||||
DisableFlagsInUseLine: true,
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
@ -35,7 +35,8 @@ func newInspectCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
}
|
||||
return runInspect(dockerCLI, opts)
|
||||
},
|
||||
ValidArgsFunction: completeContextNames(dockerCLI, -1, false),
|
||||
ValidArgsFunction: completeContextNames(dockerCLI, -1, false),
|
||||
DisableFlagsInUseLine: true,
|
||||
}
|
||||
|
||||
flags := cmd.Flags()
|
||||
|
||||
@ -23,7 +23,7 @@ type listOptions struct {
|
||||
quiet bool
|
||||
}
|
||||
|
||||
func newListCommand(dockerCli command.Cli) *cobra.Command {
|
||||
func newListCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
opts := &listOptions{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "ls [OPTIONS]",
|
||||
@ -31,9 +31,10 @@ func newListCommand(dockerCli command.Cli) *cobra.Command {
|
||||
Short: "List contexts",
|
||||
Args: cli.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runList(dockerCli, opts)
|
||||
return runList(dockerCLI, opts)
|
||||
},
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
DisableFlagsInUseLine: true,
|
||||
}
|
||||
|
||||
flags := cmd.Flags()
|
||||
|
||||
@ -32,7 +32,8 @@ func newRemoveCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runRemove(dockerCLI, opts, args)
|
||||
},
|
||||
ValidArgsFunction: completeContextNames(dockerCLI, -1, false),
|
||||
ValidArgsFunction: completeContextNames(dockerCLI, -1, false),
|
||||
DisableFlagsInUseLine: true,
|
||||
}
|
||||
cmd.Flags().BoolVarP(&opts.force, "force", "f", false, "Force the removal of a context in use")
|
||||
return cmd
|
||||
|
||||
@ -9,16 +9,17 @@ import (
|
||||
)
|
||||
|
||||
// newShowCommand creates a new cobra.Command for `docker context sow`
|
||||
func newShowCommand(dockerCli command.Cli) *cobra.Command {
|
||||
func newShowCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "show",
|
||||
Short: "Print the name of the current context",
|
||||
Args: cli.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
runShow(dockerCli)
|
||||
runShow(dockerCLI)
|
||||
return nil
|
||||
},
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
DisableFlagsInUseLine: true,
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
@ -51,8 +51,9 @@ func newUpdateCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
opts.name = args[0]
|
||||
return runUpdate(dockerCLI, &opts)
|
||||
},
|
||||
Long: longUpdateDescription(),
|
||||
ValidArgsFunction: completeContextNames(dockerCLI, 1, false),
|
||||
Long: longUpdateDescription(),
|
||||
ValidArgsFunction: completeContextNames(dockerCLI, 1, false),
|
||||
DisableFlagsInUseLine: true,
|
||||
}
|
||||
flags := cmd.Flags()
|
||||
flags.StringVar(&opts.description, "description", "", "Description of the context")
|
||||
|
||||
@ -19,7 +19,8 @@ func newUseCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
name := args[0]
|
||||
return runUse(dockerCLI, name)
|
||||
},
|
||||
ValidArgsFunction: completeContextNames(dockerCLI, 1, false),
|
||||
ValidArgsFunction: completeContextNames(dockerCLI, 1, false),
|
||||
DisableFlagsInUseLine: true,
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user