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

mknod: clap 3

This commit is contained in:
Terts Diepraam 2022-01-11 14:07:03 +01:00
parent c8eddad610
commit 6e39eddbc1
3 changed files with 12 additions and 15 deletions

View file

@ -16,7 +16,7 @@ name = "uu_mknod"
path = "src/mknod.rs" path = "src/mknod.rs"
[dependencies] [dependencies]
clap = { version = "2.33", features = ["wrap_help"] } clap = { version = "3.0", features = ["wrap_help", "cargo"] }
libc = "^0.2.42" libc = "^0.2.42"
uucore = { version=">=0.0.10", package="uucore", path="../../uucore", features=["mode"] } uucore = { version=">=0.0.10", package="uucore", path="../../uucore", features=["mode"] }
uucore_procs = { version=">=0.0.7", package="uucore_procs", path="../../uucore_procs" } uucore_procs = { version=">=0.0.7", package="uucore_procs", path="../../uucore_procs" }

View file

@ -143,28 +143,28 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.usage(USAGE) .override_usage(USAGE)
.after_help(LONG_HELP) .after_help(LONG_HELP)
.about(ABOUT) .about(ABOUT)
.arg( .arg(
Arg::with_name("mode") Arg::new("mode")
.short("m") .short('m')
.long("mode") .long("mode")
.value_name("MODE") .value_name("MODE")
.help("set file permission bits to MODE, not a=rw - umask"), .help("set file permission bits to MODE, not a=rw - umask"),
) )
.arg( .arg(
Arg::with_name("name") Arg::new("name")
.value_name("NAME") .value_name("NAME")
.help("name of the new file") .help("name of the new file")
.required(true) .required(true)
.index(1), .index(1),
) )
.arg( .arg(
Arg::with_name("type") Arg::new("type")
.value_name("TYPE") .value_name("TYPE")
.help("type of the new file (b, c, u or p)") .help("type of the new file (b, c, u or p)")
.required(true) .required(true)
@ -172,14 +172,14 @@ pub fn uu_app() -> App<'static, 'static> {
.index(2), .index(2),
) )
.arg( .arg(
Arg::with_name("major") Arg::new("major")
.value_name("MAJOR") .value_name("MAJOR")
.help("major file type") .help("major file type")
.validator(valid_u64) .validator(valid_u64)
.index(3), .index(3),
) )
.arg( .arg(
Arg::with_name("minor") Arg::new("minor")
.value_name("MINOR") .value_name("MINOR")
.help("minor file type") .help("minor file type")
.validator(valid_u64) .validator(valid_u64)
@ -202,7 +202,7 @@ fn get_mode(matches: &ArgMatches) -> Result<mode_t, String> {
} }
} }
fn valid_type(tpe: String) -> Result<(), String> { fn valid_type(tpe: &str) -> Result<(), String> {
// Only check the first character, to allow mnemonic usage like // Only check the first character, to allow mnemonic usage like
// 'mknod /dev/rst0 character 18 0'. // 'mknod /dev/rst0 character 18 0'.
tpe.chars() tpe.chars()
@ -217,6 +217,6 @@ fn valid_type(tpe: String) -> Result<(), String> {
}) })
} }
fn valid_u64(num: String) -> Result<(), String> { fn valid_u64(num: &str) -> Result<(), String> {
num.parse::<u64>().map(|_| ()).map_err(|_| num) num.parse::<u64>().map(|_| ()).map_err(|_| num.into())
} }

View file

@ -86,7 +86,6 @@ fn test_mknod_character_device_requires_major_and_minor() {
.arg("1") .arg("1")
.arg("c") .arg("c")
.fails() .fails()
.status_code(1)
.stderr_contains(&"Invalid value for '<MINOR>'"); .stderr_contains(&"Invalid value for '<MINOR>'");
new_ucmd!() new_ucmd!()
.arg("test_file") .arg("test_file")
@ -94,7 +93,6 @@ fn test_mknod_character_device_requires_major_and_minor() {
.arg("c") .arg("c")
.arg("1") .arg("1")
.fails() .fails()
.status_code(1)
.stderr_contains(&"Invalid value for '<MAJOR>'"); .stderr_contains(&"Invalid value for '<MAJOR>'");
} }
@ -104,7 +102,6 @@ fn test_mknod_invalid_arg() {
new_ucmd!() new_ucmd!()
.arg("--foo") .arg("--foo")
.fails() .fails()
.status_code(1)
.no_stdout() .no_stdout()
.stderr_contains(&"Found argument '--foo' which wasn't expected"); .stderr_contains(&"Found argument '--foo' which wasn't expected");
} }