1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-30 12:37:49 +00:00

numfmt: clap 3

This commit is contained in:
Terts Diepraam 2022-01-11 14:17:22 +01:00
parent 5702313e9c
commit 7cebb2563b
2 changed files with 18 additions and 14 deletions

View file

@ -15,7 +15,7 @@ edition = "2018"
path = "src/numfmt.rs" path = "src/numfmt.rs"
[dependencies] [dependencies]
clap = { version = "2.33", features = ["wrap_help"] } clap = { version = "3.0", features = ["wrap_help", "cargo"] }
uucore = { version=">=0.0.10", package="uucore", path="../../uucore" } uucore = { version=">=0.0.10", package="uucore", path="../../uucore" }
uucore_procs = { version=">=0.0.7", package="uucore_procs", path="../../uucore_procs" } uucore_procs = { version=">=0.0.7", package="uucore_procs", path="../../uucore_procs" }

View file

@ -159,7 +159,7 @@ fn parse_options(args: &ArgMatches) -> Result<NumfmtOptions> {
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let usage = usage();
let matches = uu_app().usage(&usage[..]).get_matches_from(args); let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
let result = let result =
parse_options(&matches).and_then(|options| match matches.values_of(options::NUMBER) { parse_options(&matches).and_then(|options| match matches.values_of(options::NUMBER) {
@ -178,42 +178,42 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.after_help(LONG_HELP) .after_help(LONG_HELP)
.setting(AppSettings::AllowNegativeNumbers) .setting(AppSettings::AllowNegativeNumbers)
.arg( .arg(
Arg::with_name(options::DELIMITER) Arg::new(options::DELIMITER)
.short("d") .short('d')
.long(options::DELIMITER) .long(options::DELIMITER)
.value_name("X") .value_name("X")
.help("use X instead of whitespace for field delimiter"), .help("use X instead of whitespace for field delimiter"),
) )
.arg( .arg(
Arg::with_name(options::FIELD) Arg::new(options::FIELD)
.long(options::FIELD) .long(options::FIELD)
.help("replace the numbers in these input fields (default=1) see FIELDS below") .help("replace the numbers in these input fields (default=1) see FIELDS below")
.value_name("FIELDS") .value_name("FIELDS")
.default_value(options::FIELD_DEFAULT), .default_value(options::FIELD_DEFAULT),
) )
.arg( .arg(
Arg::with_name(options::FROM) Arg::new(options::FROM)
.long(options::FROM) .long(options::FROM)
.help("auto-scale input numbers to UNITs; see UNIT below") .help("auto-scale input numbers to UNITs; see UNIT below")
.value_name("UNIT") .value_name("UNIT")
.default_value(options::FROM_DEFAULT), .default_value(options::FROM_DEFAULT),
) )
.arg( .arg(
Arg::with_name(options::TO) Arg::new(options::TO)
.long(options::TO) .long(options::TO)
.help("auto-scale output numbers to UNITs; see UNIT below") .help("auto-scale output numbers to UNITs; see UNIT below")
.value_name("UNIT") .value_name("UNIT")
.default_value(options::TO_DEFAULT), .default_value(options::TO_DEFAULT),
) )
.arg( .arg(
Arg::with_name(options::PADDING) Arg::new(options::PADDING)
.long(options::PADDING) .long(options::PADDING)
.help( .help(
"pad the output to N characters; positive N will \ "pad the output to N characters; positive N will \
@ -224,18 +224,18 @@ pub fn uu_app() -> App<'static, 'static> {
.value_name("N"), .value_name("N"),
) )
.arg( .arg(
Arg::with_name(options::HEADER) Arg::new(options::HEADER)
.long(options::HEADER) .long(options::HEADER)
.help( .help(
"print (without converting) the first N header lines; \ "print (without converting) the first N header lines; \
N defaults to 1 if not specified", N defaults to 1 if not specified",
) )
.value_name("N") .value_name("N")
.default_value(options::HEADER_DEFAULT) .default_missing_value(options::HEADER_DEFAULT)
.hide_default_value(true), .hide_default_value(true),
) )
.arg( .arg(
Arg::with_name(options::ROUND) Arg::new(options::ROUND)
.long(options::ROUND) .long(options::ROUND)
.help( .help(
"use METHOD for rounding when scaling; METHOD can be: up,\ "use METHOD for rounding when scaling; METHOD can be: up,\
@ -246,7 +246,7 @@ pub fn uu_app() -> App<'static, 'static> {
.possible_values(&["up", "down", "from-zero", "towards-zero", "nearest"]), .possible_values(&["up", "down", "from-zero", "towards-zero", "nearest"]),
) )
.arg( .arg(
Arg::with_name(options::SUFFIX) Arg::new(options::SUFFIX)
.long(options::SUFFIX) .long(options::SUFFIX)
.help( .help(
"print SUFFIX after each formatted number, and accept \ "print SUFFIX after each formatted number, and accept \
@ -254,5 +254,9 @@ pub fn uu_app() -> App<'static, 'static> {
) )
.value_name("SUFFIX"), .value_name("SUFFIX"),
) )
.arg(Arg::with_name(options::NUMBER).hidden(true).multiple(true)) .arg(
Arg::new(options::NUMBER)
.hide(true)
.multiple_occurrences(true),
)
} }