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:
@ -19,6 +19,8 @@ func newVolumeCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
Args: cli.NoArgs,
|
||||
RunE: command.ShowHelp(dockerCLI.Err()),
|
||||
Annotations: map[string]string{"version": "1.21"},
|
||||
|
||||
DisableFlagsInUseLine: true,
|
||||
}
|
||||
cmd.AddCommand(
|
||||
newCreateCommand(dockerCLI),
|
||||
|
||||
@ -35,7 +35,7 @@ type createOptions struct {
|
||||
preferredTopology opts.ListOpts
|
||||
}
|
||||
|
||||
func newCreateCommand(dockerCli command.Cli) *cobra.Command {
|
||||
func newCreateCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
options := createOptions{
|
||||
driverOpts: *opts.NewMapOpts(nil, nil),
|
||||
labels: opts.NewListOpts(opts.ValidateLabel),
|
||||
@ -56,9 +56,10 @@ func newCreateCommand(dockerCli command.Cli) *cobra.Command {
|
||||
options.name = args[0]
|
||||
}
|
||||
options.cluster = hasClusterVolumeOptionSet(cmd.Flags())
|
||||
return runCreate(cmd.Context(), dockerCli, options)
|
||||
return runCreate(cmd.Context(), dockerCLI, options)
|
||||
},
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
DisableFlagsInUseLine: true,
|
||||
}
|
||||
flags := cmd.Flags()
|
||||
flags.StringVarP(&options.driver, "driver", "d", "local", "Specify volume driver name")
|
||||
|
||||
@ -19,7 +19,7 @@ type inspectOptions struct {
|
||||
names []string
|
||||
}
|
||||
|
||||
func newInspectCommand(dockerCli command.Cli) *cobra.Command {
|
||||
func newInspectCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
var opts inspectOptions
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@ -28,9 +28,10 @@ func newInspectCommand(dockerCli command.Cli) *cobra.Command {
|
||||
Args: cli.RequiresMinArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
opts.names = args
|
||||
return runInspect(cmd.Context(), dockerCli, opts)
|
||||
return runInspect(cmd.Context(), dockerCLI, opts)
|
||||
},
|
||||
ValidArgsFunction: completion.VolumeNames(dockerCli),
|
||||
ValidArgsFunction: completion.VolumeNames(dockerCLI),
|
||||
DisableFlagsInUseLine: true,
|
||||
}
|
||||
|
||||
cmd.Flags().StringVarP(&opts.format, "format", "f", "", flagsHelper.InspectFormatHelp)
|
||||
|
||||
@ -25,7 +25,7 @@ type listOptions struct {
|
||||
filter opts.FilterOpt
|
||||
}
|
||||
|
||||
func newListCommand(dockerCli command.Cli) *cobra.Command {
|
||||
func newListCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
options := listOptions{filter: opts.NewFilterOpt()}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@ -34,9 +34,10 @@ func newListCommand(dockerCli command.Cli) *cobra.Command {
|
||||
Short: "List volumes",
|
||||
Args: cli.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runList(cmd.Context(), dockerCli, options)
|
||||
return runList(cmd.Context(), dockerCLI, options)
|
||||
},
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
DisableFlagsInUseLine: true,
|
||||
}
|
||||
|
||||
flags := cmd.Flags()
|
||||
|
||||
@ -47,8 +47,9 @@ func newPruneCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
fmt.Fprintln(dockerCLI.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))
|
||||
return nil
|
||||
},
|
||||
Annotations: map[string]string{"version": "1.25"},
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
Annotations: map[string]string{"version": "1.25"},
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
DisableFlagsInUseLine: true,
|
||||
}
|
||||
|
||||
flags := cmd.Flags()
|
||||
|
||||
@ -17,7 +17,7 @@ type removeOptions struct {
|
||||
volumes []string
|
||||
}
|
||||
|
||||
func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
|
||||
func newRemoveCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
var opts removeOptions
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@ -28,9 +28,10 @@ func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
|
||||
Args: cli.RequiresMinArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
opts.volumes = args
|
||||
return runRemove(cmd.Context(), dockerCli, &opts)
|
||||
return runRemove(cmd.Context(), dockerCLI, &opts)
|
||||
},
|
||||
ValidArgsFunction: completion.VolumeNames(dockerCli),
|
||||
ValidArgsFunction: completion.VolumeNames(dockerCLI),
|
||||
DisableFlagsInUseLine: true,
|
||||
}
|
||||
|
||||
flags := cmd.Flags()
|
||||
|
||||
@ -12,7 +12,7 @@ import (
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
func newUpdateCommand(dockerCli command.Cli) *cobra.Command {
|
||||
func newUpdateCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
var availability string
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@ -20,13 +20,14 @@ func newUpdateCommand(dockerCli command.Cli) *cobra.Command {
|
||||
Short: "Update a volume (cluster volumes only)",
|
||||
Args: cli.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runUpdate(cmd.Context(), dockerCli, args[0], availability, cmd.Flags())
|
||||
return runUpdate(cmd.Context(), dockerCLI, args[0], availability, cmd.Flags())
|
||||
},
|
||||
Annotations: map[string]string{
|
||||
"version": "1.42",
|
||||
"swarm": "manager",
|
||||
},
|
||||
ValidArgsFunction: completion.VolumeNames(dockerCli),
|
||||
ValidArgsFunction: completion.VolumeNames(dockerCLI),
|
||||
DisableFlagsInUseLine: true,
|
||||
}
|
||||
|
||||
flags := cmd.Flags()
|
||||
|
||||
Reference in New Issue
Block a user