diff --git a/src/baseapp.rs b/src/baseapp.rs index 567b54b..d572b81 100644 --- a/src/baseapp.rs +++ b/src/baseapp.rs @@ -29,24 +29,21 @@ impl Applet for BaseIntApplet { fn clap_command(&self) -> Command { Command::new(self.command()) .about(self.description()) - .arg(arg!(-f --from "source radix, by default, parse standard prefixes (0x, 0b, 0o)")) - .arg(arg!(-t --to "target radix, defaults to decimal, except if input was decimal, then default to hex")) + .arg(arg!(-f --from "source radix, by default, parse standard prefixes (0x, 0b, 0o)") + .value_parser(clap::value_parser!(u32).range(2..37))) + .arg(arg!(-t --to "target radix, defaults to decimal, except if input was decimal, then default to hex") + .value_parser(clap::value_parser!(u32).range(2..37))) .arg(arg!([value] "input value, reads from stdin in not present")) } fn parse_args(&self, args: &clap::ArgMatches) -> Result> { - let source_radix: Option = if let Some(src) = args.get_one::("from") { - Some(src.parse::().context("Could not parse 'from' radix")?) - } else { - None - }; - let target_radix: u32 = if let Some(target) = args.get_one::("to") { - target.parse().context("Could not parse 'to' radix")? + let target_radix: u32 = if let Some(target) = args.get_one::("to") { + *target } else { 10 }; Ok(Box::new(Self { - source_radix, + source_radix: args.get_one::("from").copied(), target_radix, })) }