mirror of
https://github.com/uutils/coreutils
synced 2024-09-16 06:21:12 +00:00
uniq: update to clap 4
This commit is contained in:
parent
3a234b3b09
commit
23c8d8b0ea
|
@ -15,7 +15,7 @@ edition = "2021"
|
|||
path = "src/uniq.rs"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "3.2", features = ["wrap_help", "cargo"] }
|
||||
clap = { version = "4.0", features = ["wrap_help", "cargo"] }
|
||||
strum = "0.24.1"
|
||||
strum_macros = "0.24.2"
|
||||
uucore = { version=">=0.0.16", package="uucore", path="../../uucore" }
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
// TODO remove this when https://github.com/rust-lang/rust-clippy/issues/6902 is fixed
|
||||
#![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::io::{self, stdin, stdout, BufRead, BufReader, BufWriter, Read, Write};
|
||||
use std::path::Path;
|
||||
|
@ -255,10 +255,8 @@ fn get_long_usage() -> String {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let long_usage = get_long_usage();
|
||||
|
||||
let matches = uu_app()
|
||||
.after_help(&long_usage[..])
|
||||
.after_help(get_long_usage())
|
||||
.try_get_matches_from(args)?;
|
||||
|
||||
let files: Vec<String> = matches
|
||||
|
@ -276,18 +274,18 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
};
|
||||
|
||||
let uniq = Uniq {
|
||||
repeats_only: matches.contains_id(options::REPEATED)
|
||||
repeats_only: matches.get_flag(options::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)
|
||||
|| matches.contains_id(options::GROUP),
|
||||
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)?,
|
||||
slice_start: opt_parsed(options::SKIP_CHARS, &matches)?,
|
||||
slice_stop: opt_parsed(options::CHECK_CHARS, &matches)?,
|
||||
ignore_case: matches.contains_id(options::IGNORE_CASE),
|
||||
zero_terminated: matches.contains_id(options::ZERO_TERMINATED),
|
||||
ignore_case: matches.get_flag(options::IGNORE_CASE),
|
||||
zero_terminated: matches.get_flag(options::ZERO_TERMINATED),
|
||||
};
|
||||
|
||||
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())
|
||||
.version(crate_version!())
|
||||
.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]")
|
||||
.value_name("delimit-method")
|
||||
.min_values(0)
|
||||
.max_values(1)
|
||||
.num_args(0..=1)
|
||||
.default_missing_value("none")
|
||||
.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]")
|
||||
.value_name("group-method")
|
||||
.min_values(0)
|
||||
.max_values(1)
|
||||
.num_args(0..=1)
|
||||
.default_missing_value("separate")
|
||||
.require_equals(true)
|
||||
.conflicts_with_all(&[
|
||||
|
@ -357,19 +353,22 @@ pub fn uu_app<'a>() -> Command<'a> {
|
|||
Arg::new(options::COUNT)
|
||||
.short('c')
|
||||
.long(options::COUNT)
|
||||
.help("prefix lines by the number of occurrences"),
|
||||
.help("prefix lines by the number of occurrences")
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::IGNORE_CASE)
|
||||
.short('i')
|
||||
.long(options::IGNORE_CASE)
|
||||
.help("ignore differences in case when comparing"),
|
||||
.help("ignore differences in case when comparing")
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::REPEATED)
|
||||
.short('d')
|
||||
.long(options::REPEATED)
|
||||
.help("only print duplicate lines"),
|
||||
.help("only print duplicate lines")
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::SKIP_CHARS)
|
||||
|
@ -389,19 +388,20 @@ pub fn uu_app<'a>() -> Command<'a> {
|
|||
Arg::new(options::UNIQUE)
|
||||
.short('u')
|
||||
.long(options::UNIQUE)
|
||||
.help("only print unique lines"),
|
||||
.help("only print unique lines")
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::ZERO_TERMINATED)
|
||||
.short('z')
|
||||
.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::new(ARG_FILES)
|
||||
.multiple_occurrences(true)
|
||||
.takes_value(true)
|
||||
.max_values(2)
|
||||
.action(ArgAction::Append)
|
||||
.num_args(0..=2)
|
||||
.value_hint(clap::ValueHint::FilePath),
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue