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

cut: update to clap 4

This commit is contained in:
Terts Diepraam 2022-09-29 16:37:34 +02:00
parent e8d24f97ae
commit 5556d23e21
2 changed files with 21 additions and 34 deletions

View file

@ -15,7 +15,7 @@ edition = "2021"
path = "src/cut.rs" path = "src/cut.rs"
[dependencies] [dependencies]
clap = { version = "3.2", features = ["wrap_help", "cargo"] } clap = { version = "4.0", features = ["wrap_help", "cargo"] }
uucore = { version=">=0.0.16", package="uucore", path="../../uucore" } uucore = { version=">=0.0.16", package="uucore", path="../../uucore" }
memchr = "2" memchr = "2"
bstr = "0.2" bstr = "0.2"

View file

@ -11,7 +11,7 @@
extern crate uucore; extern crate uucore;
use bstr::io::BufReadExt; use bstr::io::BufReadExt;
use clap::{crate_version, Arg, Command}; use clap::{crate_version, Arg, ArgAction, Command};
use std::fs::File; use std::fs::File;
use std::io::{stdin, stdout, BufReader, BufWriter, Read, Write}; use std::io::{stdin, stdout, BufReader, BufWriter, Read, Write};
use std::path::Path; use std::path::Path;
@ -403,7 +403,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let delimiter_is_equal = args.contains(&"-d=".to_string()); // special case let delimiter_is_equal = args.contains(&"-d=".to_string()); // special case
let matches = uu_app().try_get_matches_from(args)?; let matches = uu_app().try_get_matches_from(args)?;
let complement = matches.contains_id(options::COMPLEMENT); let complement = matches.get_flag(options::COMPLEMENT);
let mode_parse = match ( let mode_parse = match (
matches.get_one::<String>(options::BYTES), matches.get_one::<String>(options::BYTES),
@ -421,7 +421,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.unwrap_or_default() .unwrap_or_default()
.to_owned(), .to_owned(),
), ),
zero_terminated: matches.contains_id(options::ZERO_TERMINATED), zero_terminated: matches.get_flag(options::ZERO_TERMINATED),
}, },
) )
}), }),
@ -436,7 +436,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.unwrap_or_default() .unwrap_or_default()
.to_owned(), .to_owned(),
), ),
zero_terminated: matches.contains_id(options::ZERO_TERMINATED), zero_terminated: matches.get_flag(options::ZERO_TERMINATED),
}, },
) )
}), }),
@ -453,8 +453,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
None => None, None => None,
}; };
let only_delimited = matches.contains_id(options::ONLY_DELIMITED); let only_delimited = matches.get_flag(options::ONLY_DELIMITED);
let zero_terminated = matches.contains_id(options::ZERO_TERMINATED); let zero_terminated = matches.get_flag(options::ZERO_TERMINATED);
match matches.get_one::<String>(options::DELIMITER).map(|s| s.as_str()) { match matches.get_one::<String>(options::DELIMITER).map(|s| s.as_str()) {
Some(mut delim) => { Some(mut delim) => {
@ -514,7 +514,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Err("invalid input: The '--delimiter' ('-d') option only usable if printing a sequence of fields".into()) Err("invalid input: The '--delimiter' ('-d') option only usable if printing a sequence of fields".into())
} }
Mode::Bytes(_, _) | Mode::Characters(_, _) Mode::Bytes(_, _) | Mode::Characters(_, _)
if matches.contains_id(options::ONLY_DELIMITED) => if matches.get_flag(options::ONLY_DELIMITED) =>
{ {
Err("invalid input: The '--only-delimited' ('-s') option only usable if printing a sequence of fields".into()) Err("invalid input: The '--only-delimited' ('-s') option only usable if printing a sequence of fields".into())
} }
@ -534,7 +534,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())
.name(NAME) .name(NAME)
.version(crate_version!()) .version(crate_version!())
@ -546,76 +546,63 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new(options::BYTES) Arg::new(options::BYTES)
.short('b') .short('b')
.long(options::BYTES) .long(options::BYTES)
.takes_value(true)
.help("filter byte columns from the input source") .help("filter byte columns from the input source")
.allow_hyphen_values(true) .allow_hyphen_values(true)
.value_name("LIST") .value_name("LIST"),
.display_order(1),
) )
.arg( .arg(
Arg::new(options::CHARACTERS) Arg::new(options::CHARACTERS)
.short('c') .short('c')
.long(options::CHARACTERS) .long(options::CHARACTERS)
.help("alias for character mode") .help("alias for character mode")
.takes_value(true)
.allow_hyphen_values(true) .allow_hyphen_values(true)
.value_name("LIST") .value_name("LIST"),
.display_order(2),
) )
.arg( .arg(
Arg::new(options::DELIMITER) Arg::new(options::DELIMITER)
.short('d') .short('d')
.long(options::DELIMITER) .long(options::DELIMITER)
.help("specify the delimiter character that separates fields in the input source. Defaults to Tab.") .help("specify the delimiter character that separates fields in the input source. Defaults to Tab.")
.takes_value(true) .value_name("DELIM"),
.value_name("DELIM")
.display_order(3),
) )
.arg( .arg(
Arg::new(options::FIELDS) Arg::new(options::FIELDS)
.short('f') .short('f')
.long(options::FIELDS) .long(options::FIELDS)
.help("filter field columns from the input source") .help("filter field columns from the input source")
.takes_value(true)
.allow_hyphen_values(true) .allow_hyphen_values(true)
.value_name("LIST") .value_name("LIST"),
.display_order(4),
) )
.arg( .arg(
Arg::new(options::COMPLEMENT) Arg::new(options::COMPLEMENT)
.long(options::COMPLEMENT) .long(options::COMPLEMENT)
.help("invert the filter - instead of displaying only the filtered columns, display all but those columns") .help("invert the filter - instead of displaying only the filtered columns, display all but those columns")
.takes_value(false) .action(ArgAction::SetTrue),
.display_order(5),
) )
.arg( .arg(
Arg::new(options::ONLY_DELIMITED) Arg::new(options::ONLY_DELIMITED)
.short('s') .short('s')
.long(options::ONLY_DELIMITED) .long(options::ONLY_DELIMITED)
.help("in field mode, only print lines which contain the delimiter") .help("in field mode, only print lines which contain the delimiter")
.takes_value(false) .action(ArgAction::SetTrue),
.display_order(6),
) )
.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("instead of filtering columns based on line, filter columns based on \\0 (NULL character)") .help("instead of filtering columns based on line, filter columns based on \\0 (NULL character)")
.takes_value(false) .action(ArgAction::SetTrue),
.display_order(8),
) )
.arg( .arg(
Arg::new(options::OUTPUT_DELIMITER) Arg::new(options::OUTPUT_DELIMITER)
.long(options::OUTPUT_DELIMITER) .long(options::OUTPUT_DELIMITER)
.help("in field mode, replace the delimiter in output lines with this option's argument") .help("in field mode, replace the delimiter in output lines with this option's argument")
.takes_value(true) .value_name("NEW_DELIM"),
.value_name("NEW_DELIM")
.display_order(7),
) )
.arg( .arg(
Arg::new(options::FILE) Arg::new(options::FILE)
.hide(true) .hide(true)
.multiple_occurrences(true) .action(ArgAction::Append)
.value_hint(clap::ValueHint::FilePath) .value_hint(clap::ValueHint::FilePath)
) )
} }