From bf009ef2bec1798a56e20838bd0d20ce2b653372 Mon Sep 17 00:00:00 2001 From: qtfkwk Date: Fri, 23 Aug 2024 09:45:39 -0400 Subject: [PATCH] fix issue https://github.com/XAMPPRocky/tokei/issues/1147 (#1149) --- src/cli.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 2d3767c06..514684d63 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,4 +1,4 @@ -use std::process; +use std::{process, str::FromStr}; use clap::{crate_description, value_parser, Arg, ArgAction, ArgMatches}; use colored::Colorize; @@ -276,12 +276,19 @@ impl Cli { // Sorting category should be restricted by clap but parse before we do // work just in case. - let (sort, sort_reverse) = if let Some(sort) = matches.get_one::("sort") { - (Some(*sort), false) + let (sort, sort_reverse) = if let Some(sort) = matches.get_one::("sort") { + (Some(sort.clone()), false) } else { - let sort = matches.get_one::("rsort"); + let sort = matches.get_one::("rsort"); (sort.cloned(), sort.is_some()) }; + let sort = sort.map(|x| match Sort::from_str(&x) { + Ok(sort) => sort, + Err(e) => { + eprintln!("Error:\n{}", e); + process::exit(1); + } + }); // Format category is overly accepting by clap (so the user knows what // is supported) but this will fail if support is not compiled in and