Skip to content

Commit

Permalink
Merge #930
Browse files Browse the repository at this point in the history
930: Fix `is_verbose` accepting any 1-character argument. r=Emilgardis a=Alexhuszagh



Co-authored-by: Alex Huszagh <ahuszagh@gmail.com>
  • Loading branch information
bors[bot] and Alexhuszagh authored Jul 10, 2022
2 parents 77952e4 + 23f7b74 commit 15a8ae2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased] - ReleaseDate

## Fixed

- #930 - fix any parsing of 1-character subcommands

## [v0.2.3] - 2022-07-09

### Added
Expand Down
28 changes: 24 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,13 @@ fn is_verbose(arg: &str) -> bool {
match arg {
"--verbose" => true,
// cargo can handle any number of "v"s
a => a
.get(1..)
.map(|a| a.chars().all(|x| x == 'v'))
.unwrap_or_default(),
a => {
a.starts_with('-')
&& a.len() >= 2
&& a.get(1..)
.map(|a| a.chars().all(|x| x == 'v'))
.unwrap_or_default()
}
}
}

Expand Down Expand Up @@ -238,3 +241,20 @@ pub fn parse(target_list: &TargetList) -> Result<Args> {
color,
})
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn is_verbose_test() {
assert!(!is_verbose("b"));
assert!(!is_verbose("x"));
assert!(!is_verbose("-"));
assert!(!is_verbose("-V"));
assert!(is_verbose("-v"));
assert!(is_verbose("--verbose"));
assert!(is_verbose("-vvvv"));
assert!(!is_verbose("-version"));
}
}

0 comments on commit 15a8ae2

Please sign in to comment.