2
0
mirror of https://github.com/sharkdp/bat synced 2024-11-02 21:40:15 +00:00

Cleaned up terminal-width validation slightly

This commit is contained in:
Ethan P 2019-05-10 14:22:09 -07:00 committed by David Peter
parent a7e2bb86cb
commit 89fcbb2b15

View File

@ -333,8 +333,8 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
.hidden_short_help(true) .hidden_short_help(true)
.validator( .validator(
|t| { |t| {
let sign = t.chars().next().unwrap(); let is_offset = t.starts_with('+') || t.starts_with('-');
let num = if (sign == '+') || (sign == '-') { let num = if is_offset {
t.chars().skip(1).collect() t.chars().skip(1).collect()
} else { } else {
t t
@ -342,7 +342,7 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
num.parse::<u32>() num.parse::<u32>()
.map_err(|_e| "must be an offset or number") .map_err(|_e| "must be an offset or number")
.and_then(|v| if v == 0 && sign != '+' && sign != '-' { .and_then(|v| if v == 0 && !is_offset {
Err("terminal width cannot be zero".into()) Err("terminal width cannot be zero".into())
} else { } else {
Ok(()) Ok(())