mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-02 01:00:31 +00:00
Fix panic on --runs 0 (#923)
* fix: reject --runs/--max-runs 0, clamp --min-runs to 1 * Validate positive run counts with clap --------- Co-authored-by: VXNCXNX <VXNCXNX@users.noreply.github.com> Co-authored-by: David Peter <mail@david-peter.de>
This commit is contained in:
3 files changed
+37
-14
No files matched your search
+7
-14
@@ -275,22 +275,15 @@ impl Default for Options {
|
||||
impl Options {
|
||||
pub fn from_cli_arguments<'a>(matches: &ArgMatches) -> Result<Self, OptionsError<'a>> {
|
||||
let mut options = Self::default();
|
||||
let param_to_u64 = |param| {
|
||||
matches
|
||||
.get_one::<String>(param)
|
||||
.map(|n| {
|
||||
n.parse::<u64>()
|
||||
.map_err(|e| OptionsError::IntParsingError(param, e))
|
||||
})
|
||||
.transpose()
|
||||
};
|
||||
options.warmup_count = matches
|
||||
.get_one::<u64>("warmup")
|
||||
.copied()
|
||||
.unwrap_or(options.warmup_count);
|
||||
|
||||
options.warmup_count = param_to_u64("warmup")?.unwrap_or(options.warmup_count);
|
||||
let mut min_runs = matches.get_one::<u64>("min-runs").copied();
|
||||
let mut max_runs = matches.get_one::<u64>("max-runs").copied();
|
||||
|
||||
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) = matches.get_one::<u64>("runs") {
|
||||
min_runs = Some(runs);
|
||||
max_runs = Some(runs);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user