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 newNetworkCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
Args: cli.NoArgs,
|
||||
RunE: command.ShowHelp(dockerCLI.Err()),
|
||||
Annotations: map[string]string{"version": "1.21"},
|
||||
|
||||
DisableFlagsInUseLine: true,
|
||||
}
|
||||
cmd.AddCommand(
|
||||
newConnectCommand(dockerCLI),
|
||||
|
||||
@ -47,6 +47,7 @@ func newConnectCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
nw := args[0]
|
||||
return completion.ContainerNames(dockerCLI, true, not(isConnected(nw)))(cmd, args, toComplete)
|
||||
},
|
||||
DisableFlagsInUseLine: true,
|
||||
}
|
||||
|
||||
flags := cmd.Flags()
|
||||
|
||||
@ -68,7 +68,8 @@ func newCreateCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
|
||||
return runCreate(cmd.Context(), dockerCLI.Client(), dockerCLI.Out(), options)
|
||||
},
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
DisableFlagsInUseLine: true,
|
||||
}
|
||||
|
||||
flags := cmd.Flags()
|
||||
|
||||
@ -17,7 +17,7 @@ type disconnectOptions struct {
|
||||
force bool
|
||||
}
|
||||
|
||||
func newDisconnectCommand(dockerCli command.Cli) *cobra.Command {
|
||||
func newDisconnectCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
opts := disconnectOptions{}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@ -27,15 +27,16 @@ func newDisconnectCommand(dockerCli command.Cli) *cobra.Command {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
opts.network = args[0]
|
||||
opts.container = args[1]
|
||||
return runDisconnect(cmd.Context(), dockerCli.Client(), opts)
|
||||
return runDisconnect(cmd.Context(), dockerCLI.Client(), opts)
|
||||
},
|
||||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
if len(args) == 0 {
|
||||
return completion.NetworkNames(dockerCli)(cmd, args, toComplete)
|
||||
return completion.NetworkNames(dockerCLI)(cmd, args, toComplete)
|
||||
}
|
||||
network := args[0]
|
||||
return completion.ContainerNames(dockerCli, true, isConnected(network))(cmd, args, toComplete)
|
||||
return completion.ContainerNames(dockerCLI, true, isConnected(network))(cmd, args, toComplete)
|
||||
},
|
||||
DisableFlagsInUseLine: true,
|
||||
}
|
||||
|
||||
flags := cmd.Flags()
|
||||
|
||||
@ -33,7 +33,8 @@ func newInspectCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
opts.names = args
|
||||
return runInspect(cmd.Context(), dockerCLI.Client(), dockerCLI.Out(), opts)
|
||||
},
|
||||
ValidArgsFunction: completion.NetworkNames(dockerCLI),
|
||||
ValidArgsFunction: completion.NetworkNames(dockerCLI),
|
||||
DisableFlagsInUseLine: true,
|
||||
}
|
||||
|
||||
cmd.Flags().StringVarP(&opts.format, "format", "f", "", flagsHelper.InspectFormatHelp)
|
||||
|
||||
@ -21,7 +21,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{
|
||||
@ -30,9 +30,10 @@ func newListCommand(dockerCli command.Cli) *cobra.Command {
|
||||
Short: "List networks",
|
||||
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()
|
||||
|
||||
@ -43,7 +43,8 @@ func newPruneCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Annotations: map[string]string{"version": "1.25"},
|
||||
Annotations: map[string]string{"version": "1.25"},
|
||||
DisableFlagsInUseLine: true,
|
||||
}
|
||||
|
||||
flags := cmd.Flags()
|
||||
|
||||
@ -18,7 +18,7 @@ type removeOptions struct {
|
||||
force bool
|
||||
}
|
||||
|
||||
func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
|
||||
func newRemoveCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
var opts removeOptions
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@ -27,9 +27,10 @@ func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
|
||||
Short: "Remove one or more networks",
|
||||
Args: cli.RequiresMinArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runRemove(cmd.Context(), dockerCli, args, &opts)
|
||||
return runRemove(cmd.Context(), dockerCLI, args, &opts)
|
||||
},
|
||||
ValidArgsFunction: completion.NetworkNames(dockerCli),
|
||||
ValidArgsFunction: completion.NetworkNames(dockerCLI),
|
||||
DisableFlagsInUseLine: true,
|
||||
}
|
||||
|
||||
flags := cmd.Flags()
|
||||
|
||||
Reference in New Issue
Block a user