Ability to apply a setting to all args #3002
Labels
A-builder
Area: Builder API
A-derive
Area: #[derive]` macro API
C-enhancement
Category: Raise on the bar on expectations
S-waiting-on-decision
Status: Waiting on a go/no-go before implementing
Use Cases
app.mut_args(|arg| Some(arg.setting(ArgSettings::HideEnvValues)))
". See Add newApp::mut_args
for mutating all arguments #2966AppSettings::AllArgsOverrideSelf
is arg configuration that we want to apply everywhere. Rather than creating specialized arguments, is there a different way?clap_derive
should be WYSIWYG #2808 is to set the same display order on all argumentsApp::help_heading
allows applyingArg:help_heading
to all future arguments to take advantage of the natural grouping of arguments when adding them.Note: in some cases, users will want this to apply globally (ie to all subcommand args)
Solution Options
Note: this isn't a "pick one" but we can use a mixture
Arg
settings inApp
(ie do nothing), likeAppSettings::AllArgsOverrideSelf
App::help_heading
App::next_display_order
for Builder andclap_derive
should be WYSIWYG #2808mut_arg
to manually apply a setting (ie do nothing, see fix: Loosen reflection lifetimes #2976)App::mut_args
for mutating all arguments #2966 which led to it being reverted in Revert: Add new App::mut_args for mutating all arguments #2966 #2994clap_derive
users (instead of callingParser
, they have to callIntoApp
andFromArgMarches
)App:args_mut(&mut self) -> impl Iterator<Item = &mut Arg>
.clap_derive
users (instead of callingParser
, they have to callIntoApp
andFromArgMarches
)App::arg_setting
ArgSettings
, so doesn't help withAppSettings::AllArgsOverrideSelf
ordisplay_order
mut_args
, modeled aftermut_arg
(see Add newApp::mut_args
for mutating all arguments #2966, Revert: Add new App::mut_args for mutating all arguments #2966 #2994)bool
?)mut_args
above butFn
doesn't have a return typemut_arg
assumes you are calling it on an arg you intend to keep, so an implicit--version
becomes explicit, making it show up when you might have disabled itApp::mut_args
for mutating all arguments #2966 carried this policy forward but provided a return value to avoid adding disabled args--version
implicitApp::default_arg(arg: Arg)
orApp::mut_default_arg
is layered underneath each argalias
orlong
)App::override_arg(arg: Arg)
orApp::mut_override_arg
is layered on top of each argalias
orlong
)For when to apply these to subcommands, we could
global_
variant of any function, like today's ``global_settings`global: bool
orscope: enum Scope { Local, Inherit }
argument in any functionalias
(used for subcommands)The text was updated successfully, but these errors were encountered: