1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-17 12:16:17 +00:00

fmt: clap 3

This commit is contained in:
Terts Diepraam 2022-01-11 13:31:44 +01:00
parent df5bf0c2a4
commit e3e35cb1a9
2 changed files with 33 additions and 29 deletions

View file

@ -15,7 +15,7 @@ edition = "2018"
path = "src/fmt.rs" path = "src/fmt.rs"
[dependencies] [dependencies]
clap = { version = "2.33", features = ["wrap_help"] } clap = { version = "3.0", features = ["wrap_help", "cargo"] }
libc = "0.2.42" libc = "0.2.42"
unicode-width = "0.1.5" unicode-width = "0.1.5"
uucore = { version=">=0.0.10", package="uucore", path="../../uucore" } uucore = { version=">=0.0.10", package="uucore", path="../../uucore" }

View file

@ -71,7 +71,7 @@ pub struct FmtOptions {
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 mut files: Vec<String> = matches let mut files: Vec<String> = matches
.values_of(ARG_FILES) .values_of(ARG_FILES)
@ -222,13 +222,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Ok(()) Ok(())
} }
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)
.arg( .arg(
Arg::with_name(OPT_CROWN_MARGIN) Arg::new(OPT_CROWN_MARGIN)
.short("c") .short('c')
.long(OPT_CROWN_MARGIN) .long(OPT_CROWN_MARGIN)
.help( .help(
"First and second line of paragraph \ "First and second line of paragraph \
@ -238,8 +238,8 @@ pub fn uu_app() -> App<'static, 'static> {
), ),
) )
.arg( .arg(
Arg::with_name(OPT_TAGGED_PARAGRAPH) Arg::new(OPT_TAGGED_PARAGRAPH)
.short("t") .short('t')
.long("tagged-paragraph") .long("tagged-paragraph")
.help( .help(
"Like -c, except that the first and second line of a paragraph *must* \ "Like -c, except that the first and second line of a paragraph *must* \
@ -247,8 +247,8 @@ pub fn uu_app() -> App<'static, 'static> {
), ),
) )
.arg( .arg(
Arg::with_name(OPT_PRESERVE_HEADERS) Arg::new(OPT_PRESERVE_HEADERS)
.short("m") .short('m')
.long("preserve-headers") .long("preserve-headers")
.help( .help(
"Attempt to detect and preserve mail headers in the input. \ "Attempt to detect and preserve mail headers in the input. \
@ -256,14 +256,14 @@ pub fn uu_app() -> App<'static, 'static> {
), ),
) )
.arg( .arg(
Arg::with_name(OPT_SPLIT_ONLY) Arg::new(OPT_SPLIT_ONLY)
.short("s") .short('s')
.long("split-only") .long("split-only")
.help("Split lines only, do not reflow."), .help("Split lines only, do not reflow."),
) )
.arg( .arg(
Arg::with_name(OPT_UNIFORM_SPACING) Arg::new(OPT_UNIFORM_SPACING)
.short("u") .short('u')
.long("uniform-spacing") .long("uniform-spacing")
.help( .help(
"Insert exactly one \ "Insert exactly one \
@ -274,8 +274,8 @@ pub fn uu_app() -> App<'static, 'static> {
), ),
) )
.arg( .arg(
Arg::with_name(OPT_PREFIX) Arg::new(OPT_PREFIX)
.short("p") .short('p')
.long("prefix") .long("prefix")
.help( .help(
"Reformat only lines \ "Reformat only lines \
@ -286,8 +286,8 @@ pub fn uu_app() -> App<'static, 'static> {
.value_name("PREFIX"), .value_name("PREFIX"),
) )
.arg( .arg(
Arg::with_name(OPT_SKIP_PREFIX) Arg::new(OPT_SKIP_PREFIX)
.short("P") .short('P')
.long("skip-prefix") .long("skip-prefix")
.help( .help(
"Do not reformat lines \ "Do not reformat lines \
@ -297,8 +297,8 @@ pub fn uu_app() -> App<'static, 'static> {
.value_name("PSKIP"), .value_name("PSKIP"),
) )
.arg( .arg(
Arg::with_name(OPT_EXACT_PREFIX) Arg::new(OPT_EXACT_PREFIX)
.short("x") .short('x')
.long("exact-prefix") .long("exact-prefix")
.help( .help(
"PREFIX must match at the \ "PREFIX must match at the \
@ -306,8 +306,8 @@ pub fn uu_app() -> App<'static, 'static> {
), ),
) )
.arg( .arg(
Arg::with_name(OPT_EXACT_SKIP_PREFIX) Arg::new(OPT_EXACT_SKIP_PREFIX)
.short("X") .short('X')
.long("exact-skip-prefix") .long("exact-skip-prefix")
.help( .help(
"PSKIP must match at the \ "PSKIP must match at the \
@ -315,26 +315,26 @@ pub fn uu_app() -> App<'static, 'static> {
), ),
) )
.arg( .arg(
Arg::with_name(OPT_WIDTH) Arg::new(OPT_WIDTH)
.short("w") .short('w')
.long("width") .long("width")
.help("Fill output lines up to a maximum of WIDTH columns, default 79.") .help("Fill output lines up to a maximum of WIDTH columns, default 79.")
.value_name("WIDTH"), .value_name("WIDTH"),
) )
.arg( .arg(
Arg::with_name(OPT_GOAL) Arg::new(OPT_GOAL)
.short("g") .short('g')
.long("goal") .long("goal")
.help("Goal width, default ~0.94*WIDTH. Must be less than WIDTH.") .help("Goal width, default ~0.94*WIDTH. Must be less than WIDTH.")
.value_name("GOAL"), .value_name("GOAL"),
) )
.arg(Arg::with_name(OPT_QUICK).short("q").long("quick").help( .arg(Arg::new(OPT_QUICK).short('q').long("quick").help(
"Break lines more quickly at the \ "Break lines more quickly at the \
expense of a potentially more ragged appearance.", expense of a potentially more ragged appearance.",
)) ))
.arg( .arg(
Arg::with_name(OPT_TAB_WIDTH) Arg::new(OPT_TAB_WIDTH)
.short("T") .short('T')
.long("tab-width") .long("tab-width")
.help( .help(
"Treat tabs as TABWIDTH spaces for \ "Treat tabs as TABWIDTH spaces for \
@ -343,5 +343,9 @@ pub fn uu_app() -> App<'static, 'static> {
) )
.value_name("TABWIDTH"), .value_name("TABWIDTH"),
) )
.arg(Arg::with_name(ARG_FILES).multiple(true).takes_value(true)) .arg(
Arg::new(ARG_FILES)
.multiple_occurrences(true)
.takes_value(true),
)
} }