summaryrefslogtreecommitdiffstats
path: root/vendor/clap/examples/tutorial_builder/04_04_custom.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/clap/examples/tutorial_builder/04_04_custom.rs')
-rw-r--r--vendor/clap/examples/tutorial_builder/04_04_custom.rs15
1 files changed, 5 insertions, 10 deletions
diff --git a/vendor/clap/examples/tutorial_builder/04_04_custom.rs b/vendor/clap/examples/tutorial_builder/04_04_custom.rs
index 3dc080505..fb40b2fc4 100644
--- a/vendor/clap/examples/tutorial_builder/04_04_custom.rs
+++ b/vendor/clap/examples/tutorial_builder/04_04_custom.rs
@@ -1,12 +1,10 @@
-// Note: this requires the `cargo` feature
-
use std::path::PathBuf;
use clap::{arg, command, value_parser, ArgAction, ErrorKind};
fn main() {
// Create application like normal
- let mut cmd = command!()
+ let mut cmd = command!() // requires `cargo` feature
// Add the version arguments
.arg(arg!(--"set-ver" <VER> "set version manually").required(false))
.arg(arg!(--major "auto inc major").action(ArgAction::SetTrue))
@@ -36,10 +34,7 @@ fn main() {
// See if --set-ver was used to set the version manually
let version = if let Some(ver) = matches.get_one::<String>("set-ver") {
- if *matches.get_one::<bool>("major").expect("defaulted by clap")
- || *matches.get_one::<bool>("minor").expect("defaulted by clap")
- || *matches.get_one::<bool>("patch").expect("defaulted by clap")
- {
+ if matches.get_flag("major") || matches.get_flag("minor") || matches.get_flag("patch") {
cmd.error(
ErrorKind::ArgumentConflict,
"Can't do relative and absolute version change",
@@ -50,9 +45,9 @@ fn main() {
} else {
// Increment the one requested (in a real program, we'd reset the lower numbers)
let (maj, min, pat) = (
- *matches.get_one::<bool>("major").expect("defaulted by clap"),
- *matches.get_one::<bool>("minor").expect("defaulted by clap"),
- *matches.get_one::<bool>("patch").expect("defaulted by clap"),
+ matches.get_flag("major"),
+ matches.get_flag("minor"),
+ matches.get_flag("patch"),
);
match (maj, min, pat) {
(true, false, false) => major += 1,