1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-01 21:47:46 +00:00

shuf: update to clap 4

This commit is contained in:
Terts Diepraam 2022-09-30 16:40:59 +02:00
parent dfdd55b428
commit 4d52449667
2 changed files with 12 additions and 20 deletions

View file

@ -15,7 +15,7 @@ edition = "2021"
path = "src/shuf.rs" path = "src/shuf.rs"
[dependencies] [dependencies]
clap = { version = "3.2", features = ["wrap_help", "cargo"] } clap = { version = "4.0", features = ["wrap_help", "cargo"] }
memchr = "2.5.0" memchr = "2.5.0"
rand = "0.8" rand = "0.8"
rand_core = "0.6" rand_core = "0.6"

View file

@ -7,7 +7,7 @@
// spell-checker:ignore (ToDO) cmdline evec seps rvec fdata // spell-checker:ignore (ToDO) cmdline evec seps rvec fdata
use clap::{crate_version, Arg, Command}; use clap::{crate_version, Arg, ArgAction, Command};
use memchr::memchr_iter; use memchr::memchr_iter;
use rand::prelude::SliceRandom; use rand::prelude::SliceRandom;
use rand::RngCore; use rand::RngCore;
@ -95,8 +95,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
random_source: matches random_source: matches
.get_one::<String>(options::RANDOM_SOURCE) .get_one::<String>(options::RANDOM_SOURCE)
.map(String::from), .map(String::from),
repeat: matches.contains_id(options::REPEAT), repeat: matches.get_flag(options::REPEAT),
sep: if matches.contains_id(options::ZERO_TERMINATED) { sep: if matches.get_flag(options::ZERO_TERMINATED) {
0x00_u8 0x00_u8
} else { } else {
0x0a_u8 0x0a_u8
@ -125,30 +125,28 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Ok(()) Ok(())
} }
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)
.about(ABOUT) .about(ABOUT)
.version(crate_version!()) .version(crate_version!())
.override_usage(format_usage(USAGE)) .override_usage(format_usage(USAGE))
.infer_long_args(true) .infer_long_args(true)
.args_override_self(true)
.arg( .arg(
Arg::new(options::ECHO) Arg::new(options::ECHO)
.short('e') .short('e')
.long(options::ECHO) .long(options::ECHO)
.takes_value(true)
.value_name("ARG") .value_name("ARG")
.help("treat each ARG as an input line") .help("treat each ARG as an input line")
.multiple_occurrences(true)
.use_value_delimiter(false) .use_value_delimiter(false)
.min_values(0) .num_args(0..)
.conflicts_with(options::INPUT_RANGE), .conflicts_with(options::INPUT_RANGE),
) )
.arg( .arg(
Arg::new(options::INPUT_RANGE) Arg::new(options::INPUT_RANGE)
.short('i') .short('i')
.long(options::INPUT_RANGE) .long(options::INPUT_RANGE)
.takes_value(true)
.value_name("LO-HI") .value_name("LO-HI")
.help("treat each number LO through HI as an input line") .help("treat each number LO through HI as an input line")
.conflicts_with(options::FILE), .conflicts_with(options::FILE),
@ -157,8 +155,6 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new(options::HEAD_COUNT) Arg::new(options::HEAD_COUNT)
.short('n') .short('n')
.long(options::HEAD_COUNT) .long(options::HEAD_COUNT)
.takes_value(true)
.multiple_occurrences(true)
.value_name("COUNT") .value_name("COUNT")
.help("output at most COUNT lines"), .help("output at most COUNT lines"),
) )
@ -166,7 +162,6 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new(options::OUTPUT) Arg::new(options::OUTPUT)
.short('o') .short('o')
.long(options::OUTPUT) .long(options::OUTPUT)
.takes_value(true)
.value_name("FILE") .value_name("FILE")
.help("write result to FILE instead of standard output") .help("write result to FILE instead of standard output")
.value_hint(clap::ValueHint::FilePath), .value_hint(clap::ValueHint::FilePath),
@ -174,7 +169,6 @@ pub fn uu_app<'a>() -> Command<'a> {
.arg( .arg(
Arg::new(options::RANDOM_SOURCE) Arg::new(options::RANDOM_SOURCE)
.long(options::RANDOM_SOURCE) .long(options::RANDOM_SOURCE)
.takes_value(true)
.value_name("FILE") .value_name("FILE")
.help("get random bytes from FILE") .help("get random bytes from FILE")
.value_hint(clap::ValueHint::FilePath), .value_hint(clap::ValueHint::FilePath),
@ -183,19 +177,17 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new(options::REPEAT) Arg::new(options::REPEAT)
.short('r') .short('r')
.long(options::REPEAT) .long(options::REPEAT)
.help("output lines can be repeated"), .help("output lines can be repeated")
.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("line delimiter is NUL, not newline"), .help("line delimiter is NUL, not newline")
) .action(ArgAction::SetTrue),
.arg(
Arg::new(options::FILE)
.takes_value(true)
.value_hint(clap::ValueHint::FilePath),
) )
.arg(Arg::new(options::FILE).value_hint(clap::ValueHint::FilePath))
} }
fn read_input_file(filename: &str) -> UResult<Vec<u8>> { fn read_input_file(filename: &str) -> UResult<Vec<u8>> {