diff options
Diffstat (limited to 'vendor/clap/examples')
18 files changed, 71 insertions, 68 deletions
diff --git a/vendor/clap/examples/cargo-example-derive.rs b/vendor/clap/examples/cargo-example-derive.rs index d9603db89..dfdd799fc 100644 --- a/vendor/clap/examples/cargo-example-derive.rs +++ b/vendor/clap/examples/cargo-example-derive.rs @@ -3,18 +3,18 @@ use clap::Parser; #[derive(Parser)] // requires `derive` feature #[command(name = "cargo")] #[command(bin_name = "cargo")] -enum Cargo { - ExampleDerive(ExampleDerive), +enum CargoCli { + ExampleDerive(ExampleDeriveArgs), } #[derive(clap::Args)] #[command(author, version, about, long_about = None)] -struct ExampleDerive { +struct ExampleDeriveArgs { #[arg(long)] manifest_path: Option<std::path::PathBuf>, } fn main() { - let Cargo::ExampleDerive(args) = Cargo::parse(); + let CargoCli::ExampleDerive(args) = CargoCli::parse(); println!("{:?}", args.manifest_path); } diff --git a/vendor/clap/examples/derive_ref/augment_args.rs b/vendor/clap/examples/derive_ref/augment_args.rs index 458beb44c..39d837cfa 100644 --- a/vendor/clap/examples/derive_ref/augment_args.rs +++ b/vendor/clap/examples/derive_ref/augment_args.rs @@ -23,5 +23,5 @@ fn main() { let derived_matches = DerivedArgs::from_arg_matches(&matches) .map_err(|err| err.exit()) .unwrap(); - println!("Value of derived: {:#?}", derived_matches); + println!("Value of derived: {derived_matches:#?}"); } diff --git a/vendor/clap/examples/derive_ref/augment_subcommands.rs b/vendor/clap/examples/derive_ref/augment_subcommands.rs index 577527500..51cbe75d2 100644 --- a/vendor/clap/examples/derive_ref/augment_subcommands.rs +++ b/vendor/clap/examples/derive_ref/augment_subcommands.rs @@ -17,5 +17,5 @@ fn main() { let derived_subcommands = Subcommands::from_arg_matches(&matches) .map_err(|err| err.exit()) .unwrap(); - println!("Derived subcommands: {:#?}", derived_subcommands); + println!("Derived subcommands: {derived_subcommands:#?}"); } diff --git a/vendor/clap/examples/derive_ref/flatten_hand_args.rs b/vendor/clap/examples/derive_ref/flatten_hand_args.rs index 2ceeb7c0f..36aac0932 100644 --- a/vendor/clap/examples/derive_ref/flatten_hand_args.rs +++ b/vendor/clap/examples/derive_ref/flatten_hand_args.rs @@ -87,5 +87,5 @@ struct Cli { fn main() { let args = Cli::parse(); - println!("{:#?}", args); + println!("{args:#?}"); } diff --git a/vendor/clap/examples/derive_ref/hand_subcommand.rs b/vendor/clap/examples/derive_ref/hand_subcommand.rs index 5ea169cd1..ebaa60d5d 100644 --- a/vendor/clap/examples/derive_ref/hand_subcommand.rs +++ b/vendor/clap/examples/derive_ref/hand_subcommand.rs @@ -69,11 +69,11 @@ impl Subcommand for CliSub { struct Cli { #[arg(short, long)] top_level: bool, - #[clap(subcommand)] + #[command(subcommand)] subcommand: CliSub, } fn main() { let args = Cli::parse(); - println!("{:#?}", args); + println!("{args:#?}"); } diff --git a/vendor/clap/examples/derive_ref/interop_tests.md b/vendor/clap/examples/derive_ref/interop_tests.md index a7bcc7e7d..b29e2d52d 100644 --- a/vendor/clap/examples/derive_ref/interop_tests.md +++ b/vendor/clap/examples/derive_ref/interop_tests.md @@ -142,7 +142,7 @@ $ interop_hand_subcommand add --unknown ? failed error: unexpected argument '--unknown' found - note: to pass '--unknown' as a value, use '-- --unknown' + tip: to pass '--unknown' as a value, use '-- --unknown' Usage: interop_hand_subcommand[EXE] add [NAME]... diff --git a/vendor/clap/examples/git-derive.md b/vendor/clap/examples/git-derive.md index b5c4794d3..57edb612e 100644 --- a/vendor/clap/examples/git-derive.md +++ b/vendor/clap/examples/git-derive.md @@ -102,13 +102,13 @@ Options: -h, --help Print help $ git-derive stash -m "Prototype" -Pushing StashPush { message: Some("Prototype") } +Pushing StashPushArgs { message: Some("Prototype") } $ git-derive stash pop Popping None $ git-derive stash push -m "Prototype" -Pushing StashPush { message: Some("Prototype") } +Pushing StashPushArgs { message: Some("Prototype") } $ git-derive stash pop Popping None diff --git a/vendor/clap/examples/git-derive.rs b/vendor/clap/examples/git-derive.rs index 519982d1b..ad82e0cea 100644 --- a/vendor/clap/examples/git-derive.rs +++ b/vendor/clap/examples/git-derive.rs @@ -53,7 +53,7 @@ enum Commands { #[arg(required = true)] path: Vec<PathBuf>, }, - Stash(Stash), + Stash(StashArgs), #[command(external_subcommand)] External(Vec<OsString>), } @@ -76,23 +76,23 @@ impl std::fmt::Display for ColorWhen { #[derive(Debug, Args)] #[command(args_conflicts_with_subcommands = true)] -struct Stash { +struct StashArgs { #[command(subcommand)] command: Option<StashCommands>, #[command(flatten)] - push: StashPush, + push: StashPushArgs, } #[derive(Debug, Subcommand)] enum StashCommands { - Push(StashPush), + Push(StashPushArgs), Pop { stash: Option<String> }, Apply { stash: Option<String> }, } #[derive(Debug, Args)] -struct StashPush { +struct StashPushArgs { #[arg(short, long)] message: Option<String>, } @@ -102,7 +102,7 @@ fn main() { match args.command { Commands::Clone { remote } => { - println!("Cloning {}", remote); + println!("Cloning {remote}"); } Commands::Diff { mut base, @@ -136,22 +136,22 @@ fn main() { ); } Commands::Push { remote } => { - println!("Pushing to {}", remote); + println!("Pushing to {remote}"); } Commands::Add { path } => { - println!("Adding {:?}", path); + println!("Adding {path:?}"); } Commands::Stash(stash) => { let stash_cmd = stash.command.unwrap_or(StashCommands::Push(stash.push)); match stash_cmd { StashCommands::Push(push) => { - println!("Pushing {:?}", push); + println!("Pushing {push:?}"); } StashCommands::Pop { stash } => { - println!("Popping {:?}", stash); + println!("Popping {stash:?}"); } StashCommands::Apply { stash } => { - println!("Applying {:?}", stash); + println!("Applying {stash:?}"); } } } diff --git a/vendor/clap/examples/git.rs b/vendor/clap/examples/git.rs index 8a2fcc72d..bd05e5315 100644 --- a/vendor/clap/examples/git.rs +++ b/vendor/clap/examples/git.rs @@ -86,7 +86,7 @@ fn main() { let base = base.unwrap_or("stage"); let head = head.unwrap_or("worktree"); let path = path.unwrap_or(""); - println!("Diffing {}..{} {} (color={})", base, head, path, color); + println!("Diffing {base}..{head} {path} (color={color})"); } Some(("push", sub_matches)) => { println!( @@ -100,22 +100,22 @@ fn main() { .into_iter() .flatten() .collect::<Vec<_>>(); - println!("Adding {:?}", paths); + println!("Adding {paths:?}"); } Some(("stash", sub_matches)) => { let stash_command = sub_matches.subcommand().unwrap_or(("push", sub_matches)); match stash_command { ("apply", sub_matches) => { let stash = sub_matches.get_one::<String>("STASH"); - println!("Applying {:?}", stash); + println!("Applying {stash:?}"); } ("pop", sub_matches) => { let stash = sub_matches.get_one::<String>("STASH"); - println!("Popping {:?}", stash); + println!("Popping {stash:?}"); } ("push", sub_matches) => { let message = sub_matches.get_one::<String>("message"); - println!("Pushing {:?}", message); + println!("Pushing {message:?}"); } (name, _) => { unreachable!("Unsupported subcommand `{}`", name) @@ -128,9 +128,9 @@ fn main() { .into_iter() .flatten() .collect::<Vec<_>>(); - println!("Calling out to {:?} with {:?}", ext, args); + println!("Calling out to {ext:?} with {args:?}"); } - _ => unreachable!(), // If all subcommands are defined above, anything else is unreachabe!() + _ => unreachable!(), // If all subcommands are defined above, anything else is unreachable!() } // Continued program logic goes here... diff --git a/vendor/clap/examples/pacman.rs b/vendor/clap/examples/pacman.rs index 12e7ffaf2..7ab30db95 100644 --- a/vendor/clap/examples/pacman.rs +++ b/vendor/clap/examples/pacman.rs @@ -78,7 +78,7 @@ fn main() { .map(|s| s.as_str()) .collect(); let values = packages.join(", "); - println!("Searching for {}...", values); + println!("Searching for {values}..."); return; } @@ -90,18 +90,18 @@ fn main() { let values = packages.join(", "); if sync_matches.get_flag("info") { - println!("Retrieving info for {}...", values); + println!("Retrieving info for {values}..."); } else { - println!("Installing {}...", values); + println!("Installing {values}..."); } } Some(("query", query_matches)) => { if let Some(packages) = query_matches.get_many::<String>("info") { let comma_sep = packages.map(|s| s.as_str()).collect::<Vec<_>>().join(", "); - println!("Retrieving info for {}...", comma_sep); + println!("Retrieving info for {comma_sep}..."); } else if let Some(queries) = query_matches.get_many::<String>("search") { let comma_sep = queries.map(|s| s.as_str()).collect::<Vec<_>>().join(", "); - println!("Searching Locally for {}...", comma_sep); + println!("Searching Locally for {comma_sep}..."); } else { println!("Displaying all locally installed packages..."); } diff --git a/vendor/clap/examples/repl.rs b/vendor/clap/examples/repl.rs index ef2659115..2806ac8e9 100644 --- a/vendor/clap/examples/repl.rs +++ b/vendor/clap/examples/repl.rs @@ -17,7 +17,7 @@ fn main() -> Result<(), String> { } } Err(err) => { - write!(std::io::stdout(), "{}", err).map_err(|e| e.to_string())?; + write!(std::io::stdout(), "{err}").map_err(|e| e.to_string())?; std::io::stdout().flush().map_err(|e| e.to_string())?; } } diff --git a/vendor/clap/examples/tutorial_derive/01_quick.rs b/vendor/clap/examples/tutorial_derive/01_quick.rs index 960e7ea18..0edcd251f 100644 --- a/vendor/clap/examples/tutorial_derive/01_quick.rs +++ b/vendor/clap/examples/tutorial_derive/01_quick.rs @@ -35,7 +35,7 @@ fn main() { // You can check the value provided by positional arguments, or option arguments if let Some(name) = cli.name.as_deref() { - println!("Value for name: {}", name); + println!("Value for name: {name}"); } if let Some(config_path) = cli.config.as_deref() { diff --git a/vendor/clap/examples/tutorial_derive/03_04_subcommands.rs b/vendor/clap/examples/tutorial_derive/03_04_subcommands.rs index 279a5fff5..da7c644c7 100644 --- a/vendor/clap/examples/tutorial_derive/03_04_subcommands.rs +++ b/vendor/clap/examples/tutorial_derive/03_04_subcommands.rs @@ -21,7 +21,7 @@ fn main() { // matches just as you would the top level cmd match &cli.command { Commands::Add { name } => { - println!("'myapp add' was used, name is: {:?}", name) + println!("'myapp add' was used, name is: {name:?}") } } } diff --git a/vendor/clap/examples/tutorial_derive/03_04_subcommands_alt.rs b/vendor/clap/examples/tutorial_derive/03_04_subcommands_alt.rs index 8b70dba0a..80b0ec6b9 100644 --- a/vendor/clap/examples/tutorial_derive/03_04_subcommands_alt.rs +++ b/vendor/clap/examples/tutorial_derive/03_04_subcommands_alt.rs @@ -11,11 +11,11 @@ struct Cli { #[derive(Subcommand)] enum Commands { /// Adds files to myapp - Add(Add), + Add(AddArgs), } #[derive(Args)] -struct Add { +struct AddArgs { name: Option<String>, } diff --git a/vendor/clap/examples/tutorial_derive/04_02_validate.rs b/vendor/clap/examples/tutorial_derive/04_02_validate.rs index 513084dff..3391d5b72 100644 --- a/vendor/clap/examples/tutorial_derive/04_02_validate.rs +++ b/vendor/clap/examples/tutorial_derive/04_02_validate.rs @@ -21,7 +21,7 @@ const PORT_RANGE: RangeInclusive<usize> = 1..=65535; fn port_in_range(s: &str) -> Result<u16, String> { let port: usize = s .parse() - .map_err(|_| format!("`{}` isn't a port number", s))?; + .map_err(|_| format!("`{s}` isn't a port number"))?; if PORT_RANGE.contains(&port) { Ok(port as u16) } else { diff --git a/vendor/clap/examples/tutorial_derive/04_03_relations.rs b/vendor/clap/examples/tutorial_derive/04_03_relations.rs index e36609570..8657ebe83 100644 --- a/vendor/clap/examples/tutorial_derive/04_03_relations.rs +++ b/vendor/clap/examples/tutorial_derive/04_03_relations.rs @@ -1,13 +1,26 @@ -use clap::{ArgGroup, Parser}; +use clap::{Args, Parser}; #[derive(Parser)] #[command(author, version, about, long_about = None)] -#[command(group( - ArgGroup::new("vers") - .required(true) - .args(["set_ver", "major", "minor", "patch"]), - ))] struct Cli { + #[command(flatten)] + vers: Vers, + + /// some regular input + #[arg(group = "input")] + input_file: Option<String>, + + /// some special input argument + #[arg(long, group = "input")] + spec_in: Option<String>, + + #[arg(short, requires = "input")] + config: Option<String>, +} + +#[derive(Args)] +#[group(required = true, multiple = false)] +struct Vers { /// set version manually #[arg(long, value_name = "VER")] set_ver: Option<String>, @@ -23,17 +36,6 @@ struct Cli { /// auto inc patch #[arg(long)] patch: bool, - - /// some regular input - #[arg(group = "input")] - input_file: Option<String>, - - /// some special input argument - #[arg(long, group = "input")] - spec_in: Option<String>, - - #[arg(short, requires = "input")] - config: Option<String>, } fn main() { @@ -45,21 +47,22 @@ fn main() { let mut patch = 3; // See if --set_ver was used to set the version manually - let version = if let Some(ver) = cli.set_ver.as_deref() { + let vers = &cli.vers; + let version = if let Some(ver) = vers.set_ver.as_deref() { ver.to_string() } else { // Increment the one requested (in a real program, we'd reset the lower numbers) - let (maj, min, pat) = (cli.major, cli.minor, cli.patch); + let (maj, min, pat) = (vers.major, vers.minor, vers.patch); match (maj, min, pat) { (true, _, _) => major += 1, (_, true, _) => minor += 1, (_, _, true) => patch += 1, _ => unreachable!(), }; - format!("{}.{}.{}", major, minor, patch) + format!("{major}.{minor}.{patch}") }; - println!("Version: {}", version); + println!("Version: {version}"); // Check for usage of -c if let Some(config) = cli.config.as_deref() { @@ -67,6 +70,6 @@ fn main() { .input_file .as_deref() .unwrap_or_else(|| cli.spec_in.as_deref().unwrap()); - println!("Doing work using input {} and config {}", input, config); + println!("Doing work using input {input} and config {config}"); } } diff --git a/vendor/clap/examples/tutorial_derive/04_04_custom.rs b/vendor/clap/examples/tutorial_derive/04_04_custom.rs index cbc460f19..a84b5ed5f 100644 --- a/vendor/clap/examples/tutorial_derive/04_04_custom.rs +++ b/vendor/clap/examples/tutorial_derive/04_04_custom.rs @@ -66,10 +66,10 @@ fn main() { .exit(); } }; - format!("{}.{}.{}", major, minor, patch) + format!("{major}.{minor}.{patch}") }; - println!("Version: {}", version); + println!("Version: {version}"); // Check for usage of -c if let Some(config) = cli.config.as_deref() { @@ -86,6 +86,6 @@ fn main() { ) .exit() }); - println!("Doing work using input {} and config {}", input, config); + println!("Doing work using input {input} and config {config}"); } } diff --git a/vendor/clap/examples/typed-derive.rs b/vendor/clap/examples/typed-derive.rs index bdf8a5809..8d7a84e96 100644 --- a/vendor/clap/examples/typed-derive.rs +++ b/vendor/clap/examples/typed-derive.rs @@ -54,7 +54,7 @@ where { let pos = s .find('=') - .ok_or_else(|| format!("invalid KEY=value: no `=` found in `{}`", s))?; + .ok_or_else(|| format!("invalid KEY=value: no `=` found in `{s}`"))?; Ok((s[..pos].parse()?, s[pos + 1..].parse()?)) } @@ -98,5 +98,5 @@ mod foreign_crate { fn main() { let args = Args::parse(); - println!("{:?}", args); + println!("{args:?}"); } |