Skip to content
Myr

return an error if there are more name options than commands

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Stéphane Campinas · committed by David Peter · parent 71a47c0 · Browse files · 2 files+10 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+10 added−0 removed

  • other:+10 added−0 removed

2 files+10 added−0 removed

modified:src/hyperfine/error.rs+4 added
47 unmodified lines
48#[derive(Debug)]49pub enum OptionsError {50 RunsBelowTwo,51 EmptyRunsRange,52 TooManyCommandNames(usize),53}5455impl fmt::Display for OptionsError {56 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {57 match *self {58 OptionsError::EmptyRunsRange => write!(f, "Empty runs range"),59 OptionsError::RunsBelowTwo => write!(f, "Number of runs below two"),60 OptionsError::TooManyCommandNames(n) => {61 write!(f, "Too many --command-name options: expected {} at most", n)62 }63 }64 }65}66
1 unmodified line
modified:src/main.rs+6 added
128 unmodified lines
129130 options.names = matches131 .values_of("command-name")132 .map(|values| values.map(String::from).collect::<Vec<String>>());133 if let Some(ref names) = options.names {134 let command_strings = matches.values_of("command").unwrap();135 if names.len() > command_strings.len() {136 return Err(OptionsError::TooManyCommandNames(command_strings.len()));137 }138 }139140 options.preparation_command = matches141 .values_of("prepare")142 .map(|values| values.map(String::from).collect::<Vec<String>>());
189 unmodified lines