1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

uniq: update to clap 4

This commit is contained in:
Terts Diepraam 2022-10-01 11:57:51 +02:00
parent 3a234b3b09
commit 23c8d8b0ea
2 changed files with 23 additions and 23 deletions

View file

@ -15,7 +15,7 @@ edition = "2021"
path = "src/uniq.rs" path = "src/uniq.rs"
[dependencies] [dependencies]
clap = { version = "3.2", features = ["wrap_help", "cargo"] } clap = { version = "4.0", features = ["wrap_help", "cargo"] }
strum = "0.24.1" strum = "0.24.1"
strum_macros = "0.24.2" strum_macros = "0.24.2"
uucore = { version=">=0.0.16", package="uucore", path="../../uucore" } uucore = { version=">=0.0.16", package="uucore", path="../../uucore" }

View file

@ -8,7 +8,7 @@
// TODO remove this when https://github.com/rust-lang/rust-clippy/issues/6902 is fixed // TODO remove this when https://github.com/rust-lang/rust-clippy/issues/6902 is fixed
#![allow(clippy::use_self)] #![allow(clippy::use_self)]
use clap::{crate_version, Arg, ArgMatches, Command}; use clap::{crate_version, Arg, ArgAction, ArgMatches, Command};
use std::fs::File; use std::fs::File;
use std::io::{self, stdin, stdout, BufRead, BufReader, BufWriter, Read, Write}; use std::io::{self, stdin, stdout, BufRead, BufReader, BufWriter, Read, Write};
use std::path::Path; use std::path::Path;
@ -255,10 +255,8 @@ fn get_long_usage() -> String {
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let long_usage = get_long_usage();
let matches = uu_app() let matches = uu_app()
.after_help(&long_usage[..]) .after_help(get_long_usage())
.try_get_matches_from(args)?; .try_get_matches_from(args)?;
let files: Vec<String> = matches let files: Vec<String> = matches
@ -276,18 +274,18 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}; };
let uniq = Uniq { let uniq = Uniq {
repeats_only: matches.contains_id(options::REPEATED) repeats_only: matches.get_flag(options::REPEATED)
|| matches.contains_id(options::ALL_REPEATED), || matches.contains_id(options::ALL_REPEATED),
uniques_only: matches.contains_id(options::UNIQUE), uniques_only: matches.get_flag(options::UNIQUE),
all_repeated: matches.contains_id(options::ALL_REPEATED) all_repeated: matches.contains_id(options::ALL_REPEATED)
|| matches.contains_id(options::GROUP), || matches.contains_id(options::GROUP),
delimiters: get_delimiter(&matches), delimiters: get_delimiter(&matches),
show_counts: matches.contains_id(options::COUNT), show_counts: matches.get_flag(options::COUNT),
skip_fields: opt_parsed(options::SKIP_FIELDS, &matches)?, skip_fields: opt_parsed(options::SKIP_FIELDS, &matches)?,
slice_start: opt_parsed(options::SKIP_CHARS, &matches)?, slice_start: opt_parsed(options::SKIP_CHARS, &matches)?,
slice_stop: opt_parsed(options::CHECK_CHARS, &matches)?, slice_stop: opt_parsed(options::CHECK_CHARS, &matches)?,
ignore_case: matches.contains_id(options::IGNORE_CASE), ignore_case: matches.get_flag(options::IGNORE_CASE),
zero_terminated: matches.contains_id(options::ZERO_TERMINATED), zero_terminated: matches.get_flag(options::ZERO_TERMINATED),
}; };
if uniq.show_counts && uniq.all_repeated { if uniq.show_counts && uniq.all_repeated {
@ -303,7 +301,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
) )
} }
pub fn uu_app<'a>() -> Command<'a> { pub fn uu_app() -> Command {
Command::new(uucore::util_name()) Command::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
@ -320,8 +318,7 @@ pub fn uu_app<'a>() -> Command<'a> {
]) ])
.help("print all duplicate lines. Delimiting is done with blank lines. [default: none]") .help("print all duplicate lines. Delimiting is done with blank lines. [default: none]")
.value_name("delimit-method") .value_name("delimit-method")
.min_values(0) .num_args(0..=1)
.max_values(1)
.default_missing_value("none") .default_missing_value("none")
.require_equals(true), .require_equals(true),
) )
@ -336,8 +333,7 @@ pub fn uu_app<'a>() -> Command<'a> {
]) ])
.help("show all items, separating groups with an empty line. [default: separate]") .help("show all items, separating groups with an empty line. [default: separate]")
.value_name("group-method") .value_name("group-method")
.min_values(0) .num_args(0..=1)
.max_values(1)
.default_missing_value("separate") .default_missing_value("separate")
.require_equals(true) .require_equals(true)
.conflicts_with_all(&[ .conflicts_with_all(&[
@ -357,19 +353,22 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new(options::COUNT) Arg::new(options::COUNT)
.short('c') .short('c')
.long(options::COUNT) .long(options::COUNT)
.help("prefix lines by the number of occurrences"), .help("prefix lines by the number of occurrences")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::IGNORE_CASE) Arg::new(options::IGNORE_CASE)
.short('i') .short('i')
.long(options::IGNORE_CASE) .long(options::IGNORE_CASE)
.help("ignore differences in case when comparing"), .help("ignore differences in case when comparing")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::REPEATED) Arg::new(options::REPEATED)
.short('d') .short('d')
.long(options::REPEATED) .long(options::REPEATED)
.help("only print duplicate lines"), .help("only print duplicate lines")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::SKIP_CHARS) Arg::new(options::SKIP_CHARS)
@ -389,19 +388,20 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new(options::UNIQUE) Arg::new(options::UNIQUE)
.short('u') .short('u')
.long(options::UNIQUE) .long(options::UNIQUE)
.help("only print unique lines"), .help("only print unique lines")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::ZERO_TERMINATED) Arg::new(options::ZERO_TERMINATED)
.short('z') .short('z')
.long(options::ZERO_TERMINATED) .long(options::ZERO_TERMINATED)
.help("end lines with 0 byte, not newline"), .help("end lines with 0 byte, not newline")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(ARG_FILES) Arg::new(ARG_FILES)
.multiple_occurrences(true) .action(ArgAction::Append)
.takes_value(true) .num_args(0..=2)
.max_values(2)
.value_hint(clap::ValueHint::FilePath), .value_hint(clap::ValueHint::FilePath),
) )
} }