mirror of
https://github.com/uutils/coreutils
synced 2024-09-06 07:54:05 +00:00
Merge pull request #3850 from cakebaker/clap_replace_deprecated_value_of_os
Replace deprecated value_of_os() with get_one()
This commit is contained in:
commit
5694de7a68
|
@ -359,7 +359,7 @@ fn parse_command_line(config: clap::Command, args: impl uucore::Args) -> Result<
|
|||
|
||||
let mut files = matches.get_many::<PathBuf>("FILE").unwrap_or_default();
|
||||
|
||||
let mode = if let Some(path) = matches.value_of_os(options::REFERENCE) {
|
||||
let mode = if let Some(path) = matches.get_one::<OsString>(options::REFERENCE) {
|
||||
CommandLineMode::ReferenceBased {
|
||||
reference: PathBuf::from(path),
|
||||
}
|
||||
|
@ -369,10 +369,10 @@ fn parse_command_line(config: clap::Command, args: impl uucore::Args) -> Result<
|
|||
|| matches.contains_id(options::RANGE)
|
||||
{
|
||||
CommandLineMode::Custom {
|
||||
user: matches.value_of_os(options::USER).map(Into::into),
|
||||
role: matches.value_of_os(options::ROLE).map(Into::into),
|
||||
the_type: matches.value_of_os(options::TYPE).map(Into::into),
|
||||
range: matches.value_of_os(options::RANGE).map(Into::into),
|
||||
user: matches.get_one::<OsString>(options::USER).map(Into::into),
|
||||
role: matches.get_one::<OsString>(options::ROLE).map(Into::into),
|
||||
the_type: matches.get_one::<OsString>(options::TYPE).map(Into::into),
|
||||
range: matches.get_one::<OsString>(options::RANGE).map(Into::into),
|
||||
}
|
||||
} else if let Some(context) = files.next() {
|
||||
CommandLineMode::ContextBased {
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
|
||||
// spell-checker:ignore (ToDO) MAKEWORD addrs hashset
|
||||
|
||||
use std::collections::hash_set::HashSet;
|
||||
use std::net::ToSocketAddrs;
|
||||
use std::str;
|
||||
use std::{collections::hash_set::HashSet, ffi::OsString};
|
||||
|
||||
use clap::{crate_version, Arg, ArgMatches, Command};
|
||||
|
||||
|
@ -65,7 +65,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
#[cfg(windows)]
|
||||
let _handle = wsa::start().map_err_context(|| "failed to start Winsock".to_owned())?;
|
||||
|
||||
match matches.value_of_os(OPT_HOST) {
|
||||
match matches.get_one::<OsString>(OPT_HOST) {
|
||||
None => display_hostname(&matches),
|
||||
Some(host) => hostname::set(host).map_err_context(|| "failed to set hostname".to_owned()),
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ use memchr::{memchr3_iter, memchr_iter};
|
|||
use std::cmp::Ordering;
|
||||
use std::convert::From;
|
||||
use std::error::Error;
|
||||
use std::ffi::OsString;
|
||||
use std::fmt::Display;
|
||||
use std::fs::File;
|
||||
use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Split, Stdin, Write};
|
||||
|
@ -627,7 +628,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
settings.key1 = get_field_number(keys, key1)?;
|
||||
settings.key2 = get_field_number(keys, key2)?;
|
||||
|
||||
if let Some(value_os) = matches.value_of_os("t") {
|
||||
if let Some(value_os) = matches.get_one::<OsString>("t") {
|
||||
#[cfg(unix)]
|
||||
let value = value_os.as_bytes();
|
||||
#[cfg(not(unix))]
|
||||
|
|
|
@ -115,7 +115,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
suffix: backup_suffix,
|
||||
update: matches.contains_id(OPT_UPDATE),
|
||||
target_dir: matches
|
||||
.value_of_os(OPT_TARGET_DIRECTORY)
|
||||
.get_one::<OsString>(OPT_TARGET_DIRECTORY)
|
||||
.map(OsString::from),
|
||||
no_target_dir: matches.contains_id(OPT_NO_TARGET_DIRECTORY),
|
||||
verbose: matches.contains_id(OPT_VERBOSE),
|
||||
|
|
|
@ -226,10 +226,10 @@ fn parse_command_line(config: Command, args: impl uucore::Args) -> Result<Option
|
|||
|
||||
let mode = CommandLineMode::CustomContext {
|
||||
compute_transition_context,
|
||||
user: matches.value_of_os(options::USER).map(Into::into),
|
||||
role: matches.value_of_os(options::ROLE).map(Into::into),
|
||||
the_type: matches.value_of_os(options::TYPE).map(Into::into),
|
||||
range: matches.value_of_os(options::RANGE).map(Into::into),
|
||||
user: matches.get_one::<OsString>(options::USER).map(Into::into),
|
||||
role: matches.get_one::<OsString>(options::ROLE).map(Into::into),
|
||||
the_type: matches.get_one::<OsString>(options::TYPE).map(Into::into),
|
||||
range: matches.get_one::<OsString>(options::RANGE).map(Into::into),
|
||||
command: args.next(),
|
||||
};
|
||||
|
||||
|
|
|
@ -1201,7 +1201,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
));
|
||||
}
|
||||
|
||||
if let Some(arg) = matches.value_of_os(options::SEPARATOR) {
|
||||
if let Some(arg) = matches.get_one::<OsString>(options::SEPARATOR) {
|
||||
let mut separator = arg.to_str().ok_or_else(|| {
|
||||
UUsageError::new(
|
||||
2,
|
||||
|
|
|
@ -78,7 +78,7 @@ Try 'touch --help' for more information."##,
|
|||
)
|
||||
})?;
|
||||
let (mut atime, mut mtime) =
|
||||
if let Some(reference) = matches.value_of_os(options::sources::REFERENCE) {
|
||||
if let Some(reference) = matches.get_one::<OsString>(options::sources::REFERENCE) {
|
||||
stat(
|
||||
Path::new(reference),
|
||||
!matches.contains_id(options::NO_DEREF),
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
/* last synced with: unlink (GNU coreutils) 8.21 */
|
||||
|
||||
use std::ffi::OsString;
|
||||
use std::fs::remove_file;
|
||||
use std::path::Path;
|
||||
|
||||
|
@ -22,7 +23,7 @@ static OPT_PATH: &str = "FILE";
|
|||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
||||
let path: &Path = matches.value_of_os(OPT_PATH).unwrap().as_ref();
|
||||
let path: &Path = matches.get_one::<OsString>(OPT_PATH).unwrap().as_ref();
|
||||
|
||||
remove_file(path).map_err_context(|| format!("cannot unlink {}", path.quote()))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue