From c2fdf88ed4bbb3137f5f30ed4c7ae5a457f5bbe7 Mon Sep 17 00:00:00 2001 From: minhtrannhat Date: Wed, 20 Sep 2023 21:47:56 -0400 Subject: [PATCH] fix(lib): handles the Option for `bytes` - use the usize value_parser --- src/lib.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4e93bcd..694499b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,14 +35,14 @@ pub fn get_args() -> HeadrResult { .default_values(["-"]), ) .arg( - Arg::new("number") + Arg::new("lines") .short('n') .long("lines") .help( "Print the first K lines instead of the first 10 with the leading '-', print all but the last K lines of each file") .num_args(1) .default_value("10") - .value_parser(value_parser!(u16).range(0..)) + .value_parser(value_parser!(usize)) .action(ArgAction::Set) ) .arg( @@ -52,7 +52,7 @@ pub fn get_args() -> HeadrResult { .help( "print the first K bytes of each file; with the leading '-', print all but the last K lines of each file") .num_args(1) - .value_parser(value_parser!(u16).range(0..)) + .value_parser(value_parser!(usize)) .action(ArgAction::Set) ) .get_matches(); @@ -63,7 +63,16 @@ pub fn get_args() -> HeadrResult { .expect("Must contains valid filepaths") .cloned() .collect(), - lines: *matches.get_one("number").expect(""), - bytes: *matches.get_one("bytes").expect(""), + lines: *matches.get_one::("lines").unwrap(), + bytes: match matches.get_one::("bytes") { + Some(bytes) => Some(*bytes), + None => None, + }, }) } + +pub fn run(config: Config) -> HeadrResult<()> { + println!("{:#?}", config); + + Ok(()) +}