From 0ea16e2641b39450071b1f22efeed526e9420932 Mon Sep 17 00:00:00 2001 From: David Knaack Date: Mon, 14 Feb 2022 13:12:31 +0100 Subject: [PATCH] fix: ignore empty `--jobs` argument (#3593) --- src/context.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/context.rs b/src/context.rs index 80abe108..d0910066 100644 --- a/src/context.rs +++ b/src/context.rs @@ -18,6 +18,7 @@ use std::fs; use std::marker::PhantomData; use std::num::ParseIntError; use std::path::{Path, PathBuf}; +use std::str::FromStr; use std::string::String; use std::time::{Duration, Instant}; use terminal_size::terminal_size; @@ -617,8 +618,17 @@ impl Default for Properties { } } +/// Parse String, but treat empty strings as `None` +fn parse_trim(value: &str) -> Option> { + let value = value.trim(); + if value.is_empty() { + return None; + } + Some(F::from_str(value)) +} + fn parse_jobs(jobs: &str) -> Result { - jobs.trim().parse::() + parse_trim(jobs).unwrap_or(Ok(0)) } fn default_width() -> usize { @@ -626,10 +636,7 @@ fn default_width() -> usize { } fn parse_width(width: &str) -> Result { - if width.is_empty() { - return Ok(default_width()); - } - width.trim().parse::() + parse_trim(width).unwrap_or_else(|| Ok(default_width())) } #[cfg(test)]