return an error if there are more name options than commands

This commit is contained in:
Stéphane Campinas authored and David Peter committed 2020-10-15 22:42:44 +02:00
1 parent 71a47c0566
commit 25f8129212
2 files changed
+10

No files matched your search

+4
View File
@@ -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)
}
}
}
}
+6
View File
@@ -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")