mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-03 01:21:25 +00:00
Show error if numeric arguments can not be parsed
Shows an error message if the argument to options like '--warmup <N>'
can not be parsed:
> hyperfine --warmup xxx "sleep 1"
Error: Could not read numeric argument to '--warmup': invalid digit found in string
closes #337
This commit is contained in:
1 parent
f67763fd34
commit
46ad9bf39a
3 files changed
+23
-9
No files matched your search
+11
-6
@@ -86,20 +86,25 @@ fn main() {
|
||||
}
|
||||
|
||||
/// Build the HyperfineOptions that correspond to the given ArgMatches
|
||||
fn build_hyperfine_options(matches: &ArgMatches<'_>) -> Result<HyperfineOptions, OptionsError> {
|
||||
fn build_hyperfine_options<'a>(
|
||||
matches: &ArgMatches<'a>,
|
||||
) -> Result<HyperfineOptions, OptionsError<'a>> {
|
||||
let mut options = HyperfineOptions::default();
|
||||
let param_to_u64 = |param| {
|
||||
matches
|
||||
.value_of(param)
|
||||
.and_then(|n| u64::from_str_radix(n, 10).ok())
|
||||
.map(|n| {
|
||||
u64::from_str_radix(n, 10).map_err(|e| OptionsError::NumericParsingError(param, e))
|
||||
})
|
||||
.transpose()
|
||||
};
|
||||
|
||||
options.warmup_count = param_to_u64("warmup").unwrap_or(options.warmup_count);
|
||||
options.warmup_count = param_to_u64("warmup")?.unwrap_or(options.warmup_count);
|
||||
|
||||
let mut min_runs = param_to_u64("min-runs");
|
||||
let mut max_runs = param_to_u64("max-runs");
|
||||
let mut min_runs = param_to_u64("min-runs")?;
|
||||
let mut max_runs = param_to_u64("max-runs")?;
|
||||
|
||||
if let Some(runs) = param_to_u64("runs") {
|
||||
if let Some(runs) = param_to_u64("runs")? {
|
||||
min_runs = Some(runs);
|
||||
max_runs = Some(runs);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user