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"
[dependencies]
clap = { version = "2.33", features = ["wrap_help"] }
clap = { version = "3.0", features = ["wrap_help", "cargo"] }
libc = "^0.2.42"
uucore = { version=">=0.0.10", package="uucore", path="../../uucore", features=["mode"] }
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())
.version(crate_version!())
.usage(USAGE)
.override_usage(USAGE)
.after_help(LONG_HELP)
.about(ABOUT)
.arg(
Arg::with_name("mode")
.short("m")
Arg::new("mode")
.short('m')
.long("mode")
.value_name("MODE")
.help("set file permission bits to MODE, not a=rw - umask"),
)
.arg(
Arg::with_name("name")
Arg::new("name")
.value_name("NAME")
.help("name of the new file")
.required(true)
.index(1),
)
.arg(
Arg::with_name("type")
Arg::new("type")
.value_name("TYPE")
.help("type of the new file (b, c, u or p)")
.required(true)
@ -172,14 +172,14 @@ pub fn uu_app() -> App<'static, 'static> {
.index(2),
)
.arg(
Arg::with_name("major")
Arg::new("major")
.value_name("MAJOR")
.help("major file type")
.validator(valid_u64)
.index(3),
)
.arg(
Arg::with_name("minor")
Arg::new("minor")
.value_name("MINOR")
.help("minor file type")
.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
// 'mknod /dev/rst0 character 18 0'.
tpe.chars()
@ -217,6 +217,6 @@ fn valid_type(tpe: String) -> Result<(), String> {
})
}
fn valid_u64(num: String) -> Result<(), String> {
num.parse::<u64>().map(|_| ()).map_err(|_| num)
fn valid_u64(num: &str) -> Result<(), String> {
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("c")
.fails()
.status_code(1)
.stderr_contains(&"Invalid value for '<MINOR>'");
new_ucmd!()
.arg("test_file")
@ -94,7 +93,6 @@ fn test_mknod_character_device_requires_major_and_minor() {
.arg("c")
.arg("1")
.fails()
.status_code(1)
.stderr_contains(&"Invalid value for '<MAJOR>'");
}
@ -104,7 +102,6 @@ fn test_mknod_invalid_arg() {
new_ucmd!()
.arg("--foo")
.fails()
.status_code(1)
.no_stdout()
.stderr_contains(&"Found argument '--foo' which wasn't expected");
}