add --version to the cli

This commit is contained in:
Sylvestre Ledru
2021-09-07 22:39:36 +02:00
parent 2a39bf143b
commit ac576f50b0
2 changed files with 15 additions and 0 deletions
+4
View File
@@ -382,6 +382,10 @@ fn build_matcher_tree(
config.help_requested = true;
None
}
"-version" | "--version" => {
config.version_requested = true;
None
}
_ => return Err(From::from(format!("Unrecognized flag: '{}'", args[i]))),
};
+11
View File
@@ -19,6 +19,7 @@ pub struct Config {
max_depth: usize,
sorted_output: bool,
help_requested: bool,
version_requested: bool,
}
impl Default for Config {
@@ -29,6 +30,7 @@ impl Default for Config {
max_depth: usize::max_value(),
sorted_output: false,
help_requested: false,
version_requested: false,
}
}
}
@@ -145,6 +147,11 @@ fn do_find<'a>(args: &[&str], deps: &'a dyn Dependencies<'a>) -> Result<u64, Box
print_help();
return Ok(0);
}
if paths_and_matcher.config.version_requested {
print_version();
return Ok(0);
}
let mut found_count: u64 = 0;
for path in paths_and_matcher.paths {
found_count += process_dir(
@@ -195,6 +202,10 @@ Early alpha implementation. Currently the only expressions supported are
);
}
fn print_version() {
println!("find (Rust) {}", env!("CARGO_PKG_VERSION"));
}
/// Does all the work for find.
///
/// All main has to do is pass in the command-line args and exit the process