1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-06-26 03:32:36 +00:00

fix: ignore empty --jobs argument (#3593)

This commit is contained in:
David Knaack 2022-02-14 13:12:31 +01:00 committed by GitHub
parent e9e090e97e
commit 0ea16e2641
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,7 @@ use std::fs;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::num::ParseIntError; use std::num::ParseIntError;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::string::String; use std::string::String;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use terminal_size::terminal_size; use terminal_size::terminal_size;
@ -617,8 +618,17 @@ impl Default for Properties {
} }
} }
/// Parse String, but treat empty strings as `None`
fn parse_trim<F: FromStr>(value: &str) -> Option<Result<F, F::Err>> {
let value = value.trim();
if value.is_empty() {
return None;
}
Some(F::from_str(value))
}
fn parse_jobs(jobs: &str) -> Result<i64, ParseIntError> { fn parse_jobs(jobs: &str) -> Result<i64, ParseIntError> {
jobs.trim().parse::<i64>() parse_trim(jobs).unwrap_or(Ok(0))
} }
fn default_width() -> usize { fn default_width() -> usize {
@ -626,10 +636,7 @@ fn default_width() -> usize {
} }
fn parse_width(width: &str) -> Result<usize, ParseIntError> { fn parse_width(width: &str) -> Result<usize, ParseIntError> {
if width.is_empty() { parse_trim(width).unwrap_or_else(|| Ok(default_width()))
return Ok(default_width());
}
width.trim().parse::<usize>()
} }
#[cfg(test)] #[cfg(test)]