Skip to content

Commit

Permalink
Merge pull request #4072 from epage/group
Browse files Browse the repository at this point in the history
fix(parser)!: Store args in a group, rather than values
  • Loading branch information
epage committed Aug 12, 2022
2 parents a549457 + 41be1be commit 3c82418
Show file tree
Hide file tree
Showing 30 changed files with 603 additions and 600 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -40,6 +40,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
built-in flags and be copied to all subcommands, instead disable
the built-in flags (`Command::disable_help_flag`,
`Command::disable_version_flag`) and mark the custom flags as `global(true)`.
- Looking up a group in `ArgMatches` now returns the arg `Id`s, rather than the values.
- Various `Arg`, `Command`, and `ArgGroup` calls were switched from accepting `&[]` to `[]` via `IntoIterator`
- *(help)* Make `DeriveDisplayOrder` the default and removed the setting. To sort help, set `next_display_order(None)` (#2808)
- *(help)* Subcommand display order respects `Command::next_display_order` instead of `DeriveDisplayOrder` and using its own initial display order value (#2808)
- *(env)* Parse `--help` and `--version` like any `ArgAction::SetTrue` flag (#3776)
Expand Down
6 changes: 3 additions & 3 deletions clap_bench/benches/05_ripgrep.rs
Expand Up @@ -316,7 +316,7 @@ where
.arg(flag("help"))
.arg(flag("version").short('V'))
// First, set up primary positional/flag arguments.
.arg(arg("pattern").required_unless_present_any(&[
.arg(arg("pattern").required_unless_present_any([
"file",
"files",
"help-short",
Expand All @@ -337,9 +337,9 @@ where
flag("files")
// This should also conflict with `pattern`, but the first file
// path will actually be in `pattern`.
.conflicts_with_all(&["file", "regexp", "type-list"]),
.conflicts_with_all(["file", "regexp", "type-list"]),
)
.arg(flag("type-list").conflicts_with_all(&["file", "files", "pattern", "regexp"]))
.arg(flag("type-list").conflicts_with_all(["file", "files", "pattern", "regexp"]))
// Second, set up common flags.
.arg(flag("text").short('a'))
.arg(flag("count").short('c'))
Expand Down
2 changes: 1 addition & 1 deletion clap_bench/benches/06_rustup.rs
Expand Up @@ -263,7 +263,7 @@ fn build_cli() -> Command<'static> {
.action(ArgAction::SetTrue)
.help("Standard library API documentation"),
)
.group(ArgGroup::new("page").args(&["book", "std"])),
.group(ArgGroup::new("page").args(["book", "std"])),
)
.subcommand(
Command::new("man")
Expand Down
4 changes: 2 additions & 2 deletions clap_mangen/src/render.rs
Expand Up @@ -63,7 +63,7 @@ pub(crate) fn synopsis(roff: &mut Roff, cmd: &clap::Command) {
if let Some(value) = arg.get_value_names() {
line.push(italic(value.join(" ")));
} else {
line.push(italic(arg.get_id()));
line.push(italic(arg.get_id().as_str()));
}
line.push(roman(rhs));
line.push(roman(" "));
Expand Down Expand Up @@ -129,7 +129,7 @@ pub(crate) fn options(roff: &mut Roff, cmd: &clap::Command) {
if let Some(value) = pos.get_value_names() {
header.push(italic(value.join(" ")));
} else {
header.push(italic(pos.get_id()));
header.push(italic(pos.get_id().as_str()));
};
header.push(roman(rhs));

Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial_builder/04_03_relations.rs
Expand Up @@ -14,7 +14,7 @@ fn main() {
.group(
ArgGroup::new("vers")
.required(true)
.args(&["set-ver", "major", "minor", "patch"]),
.args(["set-ver", "major", "minor", "patch"]),
)
// Arguments can also be added to a group individually, these two arguments
// are part of the "input" group which is not required
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial_derive/04_03_relations.rs
Expand Up @@ -5,7 +5,7 @@ use clap::{ArgGroup, Parser};
#[clap(group(
ArgGroup::new("vers")
.required(true)
.args(&["set_ver", "major", "minor", "patch"]),
.args(["set_ver", "major", "minor", "patch"]),
))]
struct Cli {
/// set version manually
Expand Down

0 comments on commit 3c82418

Please sign in to comment.