Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(usage): Make dont_collapse_args_in_usage the default #4151

Merged
merged 4 commits into from Aug 30, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Expand Up @@ -61,6 +61,7 @@ MSRV is now 1.60.0

Deprecated
- `default_value_os`, `default_values_os`, `default_value_if_os`, and `default_value_ifs_os` as the non `_os` variants now accept either a `str` or an `OsStr`
- `Command::dont_collapse_args_in_usage` is now the default and is deprecated

### Features

Expand Down Expand Up @@ -92,7 +93,8 @@ Deprecated
- *(help)* Don't rely on ALL CAPS for help headers
- *(help)* List subcommands first, focusing the emphasis on them
- *(help)* Do not include global args in `cmd help help` (#4131)
- *(help)* Use `[positional]` in argument list when relevant (#4145)
- *(help)* Use `[positional]` in list when relevant (#4145)
- *(help)* Show all `[positional]` in usage
- *(version)* Use `Command::display_name` rather than `Command::bin_name`
- *(parser)* Assert on unknown args when using external subcommands (#3703)
- *(parser)* Always fill in `""` argument for external subcommands (#3263)
Expand Down
2 changes: 1 addition & 1 deletion examples/pacman.md
Expand Up @@ -56,7 +56,7 @@ pacman-sync
Synchronize packages.

Usage:
pacman[EXE] {sync|--sync|-S} [OPTIONS] [--] [package]...
pacman[EXE] {sync|--sync|-S} [OPTIONS] [package]...

Arguments:
[package]... packages
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial_builder/04_03_relations.md
Expand Up @@ -25,7 +25,7 @@ error: The following required arguments were not provided:
<--set-ver <VER>|--major|--minor|--patch>

Usage:
04_03_relations[EXE] <--set-ver <VER>|--major|--minor|--patch>
04_03_relations[EXE] <--set-ver <VER>|--major|--minor|--patch> [INPUT_FILE]

For more information try --help

Expand All @@ -37,7 +37,7 @@ $ 04_03_relations --major --minor
error: The argument '--major' cannot be used with '--minor'

Usage:
04_03_relations[EXE] <--set-ver <VER>|--major|--minor|--patch>
04_03_relations[EXE] <--set-ver <VER>|--major|--minor|--patch> [INPUT_FILE]

For more information try --help

Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial_derive/04_03_relations.md
Expand Up @@ -25,7 +25,7 @@ error: The following required arguments were not provided:
<--set-ver <VER>|--major|--minor|--patch>

Usage:
04_03_relations_derive[EXE] <--set-ver <VER>|--major|--minor|--patch>
04_03_relations_derive[EXE] <--set-ver <VER>|--major|--minor|--patch> [INPUT_FILE]

For more information try --help

Expand All @@ -37,7 +37,7 @@ $ 04_03_relations_derive --major --minor
error: The argument '--major' cannot be used with '--minor'

Usage:
04_03_relations_derive[EXE] <--set-ver <VER>|--major|--minor|--patch>
04_03_relations_derive[EXE] <--set-ver <VER>|--major|--minor|--patch> [INPUT_FILE]

For more information try --help

Expand Down
4 changes: 0 additions & 4 deletions src/builder/app_settings.rs
Expand Up @@ -43,7 +43,6 @@ pub(crate) enum AppSettings {
ArgsNegateSubcommands,
SubcommandPrecedenceOverArg,
ArgRequiredElseHelp,
DontCollapseArgsInUsage,
NextLineHelp,
DisableColoredHelp,
DisableHelpFlag,
Expand Down Expand Up @@ -86,7 +85,6 @@ bitflags! {
const DONT_DELIM_TRAIL = 1 << 24;
const ALLOW_NEG_NUMS = 1 << 25;
const DISABLE_HELP_SC = 1 << 27;
const DONT_COLLAPSE_ARGS = 1 << 28;
const ARGS_NEGATE_SCS = 1 << 29;
const PROPAGATE_VALS_DOWN = 1 << 30;
const ALLOW_MISSING_POS = 1 << 31;
Expand Down Expand Up @@ -130,8 +128,6 @@ impl_settings! { AppSettings, AppFlags,
=> Flags::COLOR_NEVER,
DontDelimitTrailingValues
=> Flags::DONT_DELIM_TRAIL,
DontCollapseArgsInUsage
=> Flags::DONT_COLLAPSE_ARGS,
DisableColoredHelp
=> Flags::DISABLE_COLORED_HELP,
DisableHelpSubcommand
Expand Down
43 changes: 13 additions & 30 deletions src/builder/command.rs
Expand Up @@ -1242,25 +1242,13 @@ impl Command {
}
}

/// Disables the automatic collapsing of positional args into `[ARGS]` inside the usage string.
///
/// **NOTE:** This choice is propagated to all child subcommands.
///
/// # Examples
///
/// ```no_run
/// # use clap::{Command, Arg};
/// Command::new("myprog")
/// .dont_collapse_args_in_usage(true)
/// .get_matches();
/// ```
#[inline]
pub fn dont_collapse_args_in_usage(self, yes: bool) -> Self {
if yes {
self.global_setting(AppSettings::DontCollapseArgsInUsage)
} else {
self.unset_global_setting(AppSettings::DontCollapseArgsInUsage)
}
#[doc(hidden)]
#[cfg_attr(
feature = "deprecated",
deprecated(since = "4.0.0", note = "This is now the default")
)]
pub fn dont_collapse_args_in_usage(self, _yes: bool) -> Self {
self
}

/// Tells `clap` *not* to print possible values when displaying help information.
Expand Down Expand Up @@ -3574,9 +3562,13 @@ impl Command {
self.is_set(AppSettings::HelpExpected)
}

/// Report whether [`Command::dont_collapse_args_in_usage`] is set
#[doc(hidden)]
#[cfg_attr(
feature = "deprecated",
deprecated(since = "4.0.0", note = "This is now the default")
)]
pub fn is_dont_collapse_args_in_usage_set(&self) -> bool {
self.is_set(AppSettings::DontCollapseArgsInUsage)
true
}

/// Report whether [`Command::infer_long_args`] is set
Expand Down Expand Up @@ -3808,11 +3800,6 @@ impl Command {
}

// Figure out implied settings
if a.is_last_set() {
// if an arg has `Last` set, we need to imply DontCollapseArgsInUsage so that args
// in the usage string don't get confused or left out.
self.settings.set(AppSettings::DontCollapseArgsInUsage);
}
a._build();
if hide_pv && a.is_takes_value_set() {
a.settings.set(ArgSettings::HidePossibleValues);
Expand Down Expand Up @@ -4305,10 +4292,6 @@ impl Command {
!self.args.is_empty()
}

pub(crate) fn has_positionals(&self) -> bool {
self.args.keys().any(|x| x.is_position())
}

pub(crate) fn has_visible_subcommands(&self) -> bool {
self.subcommands
.iter()
Expand Down