stty: update to clap 4

This commit is contained in:
Terts Diepraam 2022-10-01 00:13:54 +02:00
parent b6a4f32889
commit 5722e47474
2 changed files with 13 additions and 11 deletions

View file

@ -15,7 +15,7 @@ edition = "2021"
path = "src/stty.rs" path = "src/stty.rs"
[dependencies] [dependencies]
clap = { version = "3.1", features = ["wrap_help", "cargo"] } clap = { version = "4.0", features = ["wrap_help", "cargo"] }
uucore = { version=">=0.0.16", package="uucore", path="../../uucore" } uucore = { version=">=0.0.16", package="uucore", path="../../uucore" }
nix = { version="0.25", features = ["term"] } nix = { version="0.25", features = ["term"] }

View file

@ -7,7 +7,7 @@
mod flags; mod flags;
use clap::{crate_version, Arg, ArgMatches, Command}; use clap::{crate_version, Arg, ArgAction, ArgMatches, Command};
use nix::libc::{c_ushort, TIOCGWINSZ, TIOCSWINSZ}; use nix::libc::{c_ushort, TIOCGWINSZ, TIOCSWINSZ};
use nix::sys::termios::{ use nix::sys::termios::{
cfgetospeed, tcgetattr, tcsetattr, ControlFlags, InputFlags, LocalFlags, OutputFlags, Termios, cfgetospeed, tcgetattr, tcsetattr, ControlFlags, InputFlags, LocalFlags, OutputFlags, Termios,
@ -100,13 +100,15 @@ struct Options<'a> {
impl<'a> Options<'a> { impl<'a> Options<'a> {
fn from(matches: &'a ArgMatches) -> io::Result<Self> { fn from(matches: &'a ArgMatches) -> io::Result<Self> {
Ok(Self { Ok(Self {
all: matches.contains_id(options::ALL), all: matches.get_flag(options::ALL),
save: matches.contains_id(options::SAVE), save: matches.get_flag(options::SAVE),
file: match matches.get_one::<String>(options::FILE) { file: match matches.get_one::<String>(options::FILE) {
Some(_f) => todo!(), Some(_f) => todo!(),
None => stdout().as_raw_fd(), None => stdout().as_raw_fd(),
}, },
settings: matches.values_of(options::SETTINGS).map(|v| v.collect()), settings: matches
.get_many::<String>(options::SETTINGS)
.map(|v| v.map(|s| s.as_ref()).collect()),
}) })
} }
} }
@ -320,7 +322,7 @@ fn apply_flag<T: TermiosFlag>(
ControlFlow::Continue(()) ControlFlow::Continue(())
} }
pub fn uu_app<'a>() -> Command<'a> { pub fn uu_app() -> Command {
Command::new(uucore::util_name()) Command::new(uucore::util_name())
.name(NAME) .name(NAME)
.version(crate_version!()) .version(crate_version!())
@ -331,27 +333,27 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new(options::ALL) Arg::new(options::ALL)
.short('a') .short('a')
.long(options::ALL) .long(options::ALL)
.help("print all current settings in human-readable form"), .help("print all current settings in human-readable form")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::SAVE) Arg::new(options::SAVE)
.short('g') .short('g')
.long(options::SAVE) .long(options::SAVE)
.help("print all current settings in a stty-readable form"), .help("print all current settings in a stty-readable form")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::FILE) Arg::new(options::FILE)
.short('F') .short('F')
.long(options::FILE) .long(options::FILE)
.takes_value(true)
.value_hint(clap::ValueHint::FilePath) .value_hint(clap::ValueHint::FilePath)
.value_name("DEVICE") .value_name("DEVICE")
.help("open and use the specified DEVICE instead of stdin"), .help("open and use the specified DEVICE instead of stdin"),
) )
.arg( .arg(
Arg::new(options::SETTINGS) Arg::new(options::SETTINGS)
.takes_value(true) .action(ArgAction::Append)
.multiple_values(true)
.help("settings to change"), .help("settings to change"),
) )
} }