From 25f81292121867ddf83078acb82b74ed483f943c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Campinas?= Date: Thu, 15 Oct 2020 22:32:30 +0200 Subject: [PATCH] return an error if there are more name options than commands --- src/hyperfine/error.rs | 4 ++++ src/main.rs | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/hyperfine/error.rs b/src/hyperfine/error.rs index a2627f8..dc1e310 100644 --- a/src/hyperfine/error.rs +++ b/src/hyperfine/error.rs @@ -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) + } } } } diff --git a/src/main.rs b/src/main.rs index 855701f..a0502e4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -130,6 +130,12 @@ fn build_hyperfine_options(matches: &ArgMatches<'_>) -> Result>()); + 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")