From d92f2f6195517d7a820a568f4a13f7bc031ad692 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Fri, 30 Sep 2022 16:27:54 +0200 Subject: [PATCH] runcon: update to clap 4 --- src/uu/runcon/Cargo.toml | 2 +- src/uu/runcon/src/runcon.rs | 19 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/uu/runcon/Cargo.toml b/src/uu/runcon/Cargo.toml index ad63b0a54..fe92ca1f1 100644 --- a/src/uu/runcon/Cargo.toml +++ b/src/uu/runcon/Cargo.toml @@ -14,7 +14,7 @@ edition = "2021" path = "src/runcon.rs" [dependencies] -clap = { version = "3.2", features = ["wrap_help", "cargo"] } +clap = { version = "4.0", features = ["wrap_help", "cargo"] } uucore = { version = ">=0.0.9", package="uucore", path="../../uucore", features=["entries", "fs", "perms"] } selinux = { version = "0.3" } thiserror = { version = "1.0" } diff --git a/src/uu/runcon/src/runcon.rs b/src/uu/runcon/src/runcon.rs index 47f56a148..101cd3bee 100644 --- a/src/uu/runcon/src/runcon.rs +++ b/src/uu/runcon/src/runcon.rs @@ -3,7 +3,7 @@ use clap::builder::ValueParser; use uucore::error::{UResult, UUsageError}; -use clap::{Arg, Command}; +use clap::{Arg, ArgAction, Command}; use selinux::{OpaqueSecurityContext, SecurityClass, SecurityContext}; use uucore::format_usage; @@ -50,7 +50,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { Err(r) => { if let Error::CommandLine(ref r) = r { match r.kind() { - clap::ErrorKind::DisplayHelp | clap::ErrorKind::DisplayVersion => { + clap::error::ErrorKind::DisplayHelp + | clap::error::ErrorKind::DisplayVersion => { println!("{}", r); return Ok(()); } @@ -104,7 +105,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } } -pub fn uu_app<'a>() -> Command<'a> { +pub fn uu_app() -> Command { Command::new(uucore::util_name()) .version(VERSION) .about(ABOUT) @@ -115,14 +116,13 @@ pub fn uu_app<'a>() -> Command<'a> { Arg::new(options::COMPUTE) .short('c') .long(options::COMPUTE) - .takes_value(false) - .help("Compute process transition context before modifying."), + .help("Compute process transition context before modifying.") + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::USER) .short('u') .long(options::USER) - .takes_value(true) .value_name("USER") .help("Set user USER in the target security context.") .value_parser(ValueParser::os_string()), @@ -131,7 +131,6 @@ pub fn uu_app<'a>() -> Command<'a> { Arg::new(options::ROLE) .short('r') .long(options::ROLE) - .takes_value(true) .value_name("ROLE") .help("Set role ROLE in the target security context.") .value_parser(ValueParser::os_string()), @@ -140,7 +139,6 @@ pub fn uu_app<'a>() -> Command<'a> { Arg::new(options::TYPE) .short('t') .long(options::TYPE) - .takes_value(true) .value_name("TYPE") .help("Set type TYPE in the target security context.") .value_parser(ValueParser::os_string()), @@ -149,14 +147,13 @@ pub fn uu_app<'a>() -> Command<'a> { Arg::new(options::RANGE) .short('l') .long(options::RANGE) - .takes_value(true) .value_name("RANGE") .help("Set range RANGE in the target security context.") .value_parser(ValueParser::os_string()), ) .arg( Arg::new("ARG") - .multiple_occurrences(true) + .action(ArgAction::Append) .value_parser(ValueParser::os_string()) .value_hint(clap::ValueHint::CommandName), ) @@ -210,7 +207,7 @@ struct Options { fn parse_command_line(config: Command, args: impl uucore::Args) -> Result { let matches = config.try_get_matches_from(args)?; - let compute_transition_context = matches.contains_id(options::COMPUTE); + let compute_transition_context = matches.get_flag(options::COMPUTE); let mut args = matches .get_many::("ARG")