mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-01 08:50:19 +00:00
return an error if there are more name options than commands
This commit is contained in:
1 parent
71a47c0566
commit
25f8129212
2 files changed
+10
No files matched your search
@@ -49,6 +49,7 @@ impl Error for ParameterScanError {}
|
||||
pub enum OptionsError {
|
||||
RunsBelowTwo,
|
||||
EmptyRunsRange,
|
||||
TooManyCommandNames(usize),
|
||||
}
|
||||
|
||||
impl fmt::Display for OptionsError {
|
||||
@@ -56,6 +57,9 @@ impl fmt::Display for OptionsError {
|
||||
match *self {
|
||||
OptionsError::EmptyRunsRange => write!(f, "Empty runs range"),
|
||||
OptionsError::RunsBelowTwo => write!(f, "Number of runs below two"),
|
||||
OptionsError::TooManyCommandNames(n) => {
|
||||
write!(f, "Too many --command-name options: expected {} at most", n)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,6 +130,12 @@ fn build_hyperfine_options(matches: &ArgMatches<'_>) -> Result<HyperfineOptions,
|
||||
options.names = matches
|
||||
.values_of("command-name")
|
||||
.map(|values| values.map(String::from).collect::<Vec<String>>());
|
||||
if let Some(ref names) = options.names {
|
||||
let command_strings = matches.values_of("command").unwrap();
|
||||
if names.len() > command_strings.len() {
|
||||
return Err(OptionsError::TooManyCommandNames(command_strings.len()));
|
||||
}
|
||||
}
|
||||
|
||||
options.preparation_command = matches
|
||||
.values_of("prepare")
|
||||
|
||||
Reference in new issue
Block a user