Skip to content

Commit

Permalink
add --version to the cli
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre committed Sep 7, 2021
1 parent 2a39bf1 commit ac576f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/find/matchers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]))),
};
Expand Down
11 changes: 11 additions & 0 deletions src/find/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct Config {
max_depth: usize,
sorted_output: bool,
help_requested: bool,
version_requested: bool,
}

impl Default for Config {
Expand All @@ -29,6 +30,7 @@ impl Default for Config {
max_depth: usize::max_value(),
sorted_output: false,
help_requested: false,
version_requested: false,
}
}
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ac576f5

Please sign in to comment.