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:
parent
92e94de2d7
commit
793e540323
3 changed files with 22 additions and 24 deletions
|
@ -15,7 +15,7 @@ edition = "2018"
|
||||||
path = "src/shuf.rs"
|
path = "src/shuf.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "2.33", features = ["wrap_help"] }
|
clap = { version = "3.0", features = ["wrap_help", "cargo"] }
|
||||||
rand = "0.5"
|
rand = "0.5"
|
||||||
uucore = { version=">=0.0.10", package="uucore", path="../../uucore" }
|
uucore = { version=">=0.0.10", package="uucore", path="../../uucore" }
|
||||||
uucore_procs = { version=">=0.0.7", package="uucore_procs", path="../../uucore_procs" }
|
uucore_procs = { version=">=0.0.7", package="uucore_procs", path="../../uucore_procs" }
|
||||||
|
|
|
@ -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.
|
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 {
|
struct Options {
|
||||||
head_count: usize,
|
head_count: usize,
|
||||||
|
@ -116,27 +116,27 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uu_app() -> App<'static, 'static> {
|
pub fn uu_app<'a>() -> App<'a> {
|
||||||
App::new(uucore::util_name())
|
App::new(uucore::util_name())
|
||||||
.name(NAME)
|
.name(NAME)
|
||||||
.version(crate_version!())
|
.version(crate_version!())
|
||||||
.template(TEMPLATE)
|
.help_template(TEMPLATE)
|
||||||
.usage(USAGE)
|
.override_usage(USAGE)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::ECHO)
|
Arg::new(options::ECHO)
|
||||||
.short("e")
|
.short('e')
|
||||||
.long(options::ECHO)
|
.long(options::ECHO)
|
||||||
.takes_value(true)
|
.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(true)
|
.multiple_occurrences(true)
|
||||||
.use_delimiter(false)
|
.use_delimiter(false)
|
||||||
.min_values(0)
|
.min_values(0)
|
||||||
.conflicts_with(options::INPUT_RANGE),
|
.conflicts_with(options::INPUT_RANGE),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::INPUT_RANGE)
|
Arg::new(options::INPUT_RANGE)
|
||||||
.short("i")
|
.short('i')
|
||||||
.long(options::INPUT_RANGE)
|
.long(options::INPUT_RANGE)
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.value_name("LO-HI")
|
.value_name("LO-HI")
|
||||||
|
@ -144,41 +144,41 @@ pub fn uu_app() -> App<'static, 'static> {
|
||||||
.conflicts_with(options::FILE),
|
.conflicts_with(options::FILE),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::HEAD_COUNT)
|
Arg::new(options::HEAD_COUNT)
|
||||||
.short("n")
|
.short('n')
|
||||||
.long(options::HEAD_COUNT)
|
.long(options::HEAD_COUNT)
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.value_name("COUNT")
|
.value_name("COUNT")
|
||||||
.help("output at most COUNT lines"),
|
.help("output at most COUNT lines"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::OUTPUT)
|
Arg::new(options::OUTPUT)
|
||||||
.short("o")
|
.short('o')
|
||||||
.long(options::OUTPUT)
|
.long(options::OUTPUT)
|
||||||
.takes_value(true)
|
.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"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::RANDOM_SOURCE)
|
Arg::new(options::RANDOM_SOURCE)
|
||||||
.long(options::RANDOM_SOURCE)
|
.long(options::RANDOM_SOURCE)
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.value_name("FILE")
|
.value_name("FILE")
|
||||||
.help("get random bytes from FILE"),
|
.help("get random bytes from FILE"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(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"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(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"),
|
||||||
)
|
)
|
||||||
.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>> {
|
fn read_input_file(filename: &str) -> UResult<Vec<u8>> {
|
||||||
|
|
|
@ -154,9 +154,7 @@ fn test_shuf_echo_and_input_range_not_allowed() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["-e", "0", "-i", "0-2"])
|
.args(&["-e", "0", "-i", "0-2"])
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_contains(
|
.stderr_contains("cannot be used with");
|
||||||
"The argument '--input-range <LO-HI>' cannot be used with '--echo <ARG>...'",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -164,7 +162,7 @@ fn test_shuf_input_range_and_file_not_allowed() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["-i", "0-9", "file"])
|
.args(&["-i", "0-9", "file"])
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_contains("The argument '<file>' cannot be used with '--input-range <LO-HI>'");
|
.stderr_contains("cannot be used with");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue