fix(lib): handles the Option for bytes
- use the usize value_parser
This commit is contained in:
parent
2b1a912efe
commit
c2fdf88ed4
19
src/lib.rs
19
src/lib.rs
@ -35,14 +35,14 @@ pub fn get_args() -> HeadrResult<Config> {
|
|||||||
.default_values(["-"]),
|
.default_values(["-"]),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("number")
|
Arg::new("lines")
|
||||||
.short('n')
|
.short('n')
|
||||||
.long("lines")
|
.long("lines")
|
||||||
.help(
|
.help(
|
||||||
"Print the first K lines instead of the first 10 with the leading '-', print all but the last K lines of each file")
|
"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)
|
.num_args(1)
|
||||||
.default_value("10")
|
.default_value("10")
|
||||||
.value_parser(value_parser!(u16).range(0..))
|
.value_parser(value_parser!(usize))
|
||||||
.action(ArgAction::Set)
|
.action(ArgAction::Set)
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
@ -52,7 +52,7 @@ pub fn get_args() -> HeadrResult<Config> {
|
|||||||
.help(
|
.help(
|
||||||
"print the first K bytes of each file; with the leading '-', print all but the last K lines of each file")
|
"print the first K bytes of each file; with the leading '-', print all but the last K lines of each file")
|
||||||
.num_args(1)
|
.num_args(1)
|
||||||
.value_parser(value_parser!(u16).range(0..))
|
.value_parser(value_parser!(usize))
|
||||||
.action(ArgAction::Set)
|
.action(ArgAction::Set)
|
||||||
)
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
@ -63,7 +63,16 @@ pub fn get_args() -> HeadrResult<Config> {
|
|||||||
.expect("Must contains valid filepaths")
|
.expect("Must contains valid filepaths")
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect(),
|
.collect(),
|
||||||
lines: *matches.get_one("number").expect(""),
|
lines: *matches.get_one::<usize>("lines").unwrap(),
|
||||||
bytes: *matches.get_one("bytes").expect(""),
|
bytes: match matches.get_one::<usize>("bytes") {
|
||||||
|
Some(bytes) => Some(*bytes),
|
||||||
|
None => None,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn run(config: Config) -> HeadrResult<()> {
|
||||||
|
println!("{:#?}", config);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user