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

shuf: clap 3

This commit is contained in:
Terts Diepraam 2022-01-11 14:45:10 +01:00
parent 92e94de2d7
commit 793e540323
3 changed files with 22 additions and 24 deletions

View file

@ -15,7 +15,7 @@ edition = "2018"
path = "src/shuf.rs"
[dependencies]
clap = { version = "2.33", features = ["wrap_help"] }
clap = { version = "3.0", features = ["wrap_help", "cargo"] }
rand = "0.5"
uucore = { version=">=0.0.10", package="uucore", path="../../uucore" }
uucore_procs = { version=">=0.0.7", package="uucore_procs", path="../../uucore_procs" }

View file

@ -29,7 +29,7 @@ Write a random permutation of the input lines to standard output.
With no FILE, or when FILE is -, read standard input.
"#;
static TEMPLATE: &str = "Usage: {usage}\nMandatory arguments to long options are mandatory for short options too.\n{unified}";
static TEMPLATE: &str = "Usage: {usage}\nMandatory arguments to long options are mandatory for short options too.\n{options}";
struct Options {
head_count: usize,
@ -116,27 +116,27 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Ok(())
}
pub fn uu_app() -> App<'static, 'static> {
pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name())
.name(NAME)
.version(crate_version!())
.template(TEMPLATE)
.usage(USAGE)
.help_template(TEMPLATE)
.override_usage(USAGE)
.arg(
Arg::with_name(options::ECHO)
.short("e")
Arg::new(options::ECHO)
.short('e')
.long(options::ECHO)
.takes_value(true)
.value_name("ARG")
.help("treat each ARG as an input line")
.multiple(true)
.multiple_occurrences(true)
.use_delimiter(false)
.min_values(0)
.conflicts_with(options::INPUT_RANGE),
)
.arg(
Arg::with_name(options::INPUT_RANGE)
.short("i")
Arg::new(options::INPUT_RANGE)
.short('i')
.long(options::INPUT_RANGE)
.takes_value(true)
.value_name("LO-HI")
@ -144,41 +144,41 @@ pub fn uu_app() -> App<'static, 'static> {
.conflicts_with(options::FILE),
)
.arg(
Arg::with_name(options::HEAD_COUNT)
.short("n")
Arg::new(options::HEAD_COUNT)
.short('n')
.long(options::HEAD_COUNT)
.takes_value(true)
.value_name("COUNT")
.help("output at most COUNT lines"),
)
.arg(
Arg::with_name(options::OUTPUT)
.short("o")
Arg::new(options::OUTPUT)
.short('o')
.long(options::OUTPUT)
.takes_value(true)
.value_name("FILE")
.help("write result to FILE instead of standard output"),
)
.arg(
Arg::with_name(options::RANDOM_SOURCE)
Arg::new(options::RANDOM_SOURCE)
.long(options::RANDOM_SOURCE)
.takes_value(true)
.value_name("FILE")
.help("get random bytes from FILE"),
)
.arg(
Arg::with_name(options::REPEAT)
.short("r")
Arg::new(options::REPEAT)
.short('r')
.long(options::REPEAT)
.help("output lines can be repeated"),
)
.arg(
Arg::with_name(options::ZERO_TERMINATED)
.short("z")
Arg::new(options::ZERO_TERMINATED)
.short('z')
.long(options::ZERO_TERMINATED)
.help("line delimiter is NUL, not newline"),
)
.arg(Arg::with_name(options::FILE).takes_value(true))
.arg(Arg::new(options::FILE).takes_value(true))
}
fn read_input_file(filename: &str) -> UResult<Vec<u8>> {

View file

@ -154,9 +154,7 @@ fn test_shuf_echo_and_input_range_not_allowed() {
new_ucmd!()
.args(&["-e", "0", "-i", "0-2"])
.fails()
.stderr_contains(
"The argument '--input-range <LO-HI>' cannot be used with '--echo <ARG>...'",
);
.stderr_contains("cannot be used with");
}
#[test]
@ -164,7 +162,7 @@ fn test_shuf_input_range_and_file_not_allowed() {
new_ucmd!()
.args(&["-i", "0-9", "file"])
.fails()
.stderr_contains("The argument '<file>' cannot be used with '--input-range <LO-HI>'");
.stderr_contains("cannot be used with");
}
#[test]