Skip to content

Commit 23f7b74

Browse files
committed
Fix is_verbose accepting any 1-character argument.
1 parent 77952e4 commit 23f7b74

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased] - ReleaseDate
99

10+
## Fixed
11+
12+
- #930 - fix any parsing of 1-character subcommands
13+
1014
## [v0.2.3] - 2022-07-09
1115

1216
### Added

src/cli.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,13 @@ fn is_verbose(arg: &str) -> bool {
7272
match arg {
7373
"--verbose" => true,
7474
// cargo can handle any number of "v"s
75-
a => a
76-
.get(1..)
77-
.map(|a| a.chars().all(|x| x == 'v'))
78-
.unwrap_or_default(),
75+
a => {
76+
a.starts_with('-')
77+
&& a.len() >= 2
78+
&& a.get(1..)
79+
.map(|a| a.chars().all(|x| x == 'v'))
80+
.unwrap_or_default()
81+
}
7982
}
8083
}
8184

@@ -238,3 +241,20 @@ pub fn parse(target_list: &TargetList) -> Result<Args> {
238241
color,
239242
})
240243
}
244+
245+
#[cfg(test)]
246+
mod tests {
247+
use super::*;
248+
249+
#[test]
250+
fn is_verbose_test() {
251+
assert!(!is_verbose("b"));
252+
assert!(!is_verbose("x"));
253+
assert!(!is_verbose("-"));
254+
assert!(!is_verbose("-V"));
255+
assert!(is_verbose("-v"));
256+
assert!(is_verbose("--verbose"));
257+
assert!(is_verbose("-vvvv"));
258+
assert!(!is_verbose("-version"));
259+
}
260+
}

0 commit comments

Comments
 (0)