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

Merge pull request #3804 from cakebaker/clap_replace_deprecated_values_of

Replace deprecated values_of() with get_many()
This commit is contained in:
Sylvestre Ledru 2022-08-11 15:08:25 +02:00 committed by GitHub
commit 0f1b98c259
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
65 changed files with 133 additions and 104 deletions

View file

@ -39,7 +39,7 @@ pub mod options {
impl Config { impl Config {
pub fn from(options: &clap::ArgMatches) -> UResult<Self> { pub fn from(options: &clap::ArgMatches) -> UResult<Self> {
let file: Option<String> = match options.values_of(options::FILE) { let file: Option<String> = match options.get_many::<String>(options::FILE) {
Some(mut values) => { Some(mut values) => {
let name = values.next().unwrap(); let name = values.next().unwrap();
if let Some(extra_op) = values.next() { if let Some(extra_op) = values.next() {

View file

@ -69,7 +69,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
format!( format!(
"extra operand {}", "extra operand {}",
matches matches
.values_of(options::NAME) .get_many::<String>(options::NAME)
.unwrap() .unwrap()
.nth(2) .nth(2)
.unwrap() .unwrap()
@ -81,7 +81,11 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let suffix = if opt_suffix { let suffix = if opt_suffix {
matches.value_of(options::SUFFIX).unwrap() matches.value_of(options::SUFFIX).unwrap()
} else if !opt_multiple && matches.occurrences_of(options::NAME) > 1 { } else if !opt_multiple && matches.occurrences_of(options::NAME) > 1 {
matches.values_of(options::NAME).unwrap().nth(1).unwrap() matches
.get_many::<String>(options::NAME)
.unwrap()
.nth(1)
.unwrap()
} else { } else {
"" ""
}; };
@ -91,9 +95,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// //
let paths: Vec<_> = if multiple_paths { let paths: Vec<_> = if multiple_paths {
matches.values_of(options::NAME).unwrap().collect() matches.get_many::<String>(options::NAME).unwrap().collect()
} else { } else {
matches.values_of(options::NAME).unwrap().take(1).collect() matches
.get_many::<String>(options::NAME)
.unwrap()
.take(1)
.collect()
}; };
let line_ending = if opt_zero { "\0" } else { "\n" }; let line_ending = if opt_zero { "\0" } else { "\n" };

View file

@ -224,7 +224,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.any(|v| matches.contains_id(v)); .any(|v| matches.contains_id(v));
let squeeze_blank = matches.contains_id(options::SQUEEZE_BLANK); let squeeze_blank = matches.contains_id(options::SQUEEZE_BLANK);
let files: Vec<String> = match matches.values_of(options::FILE) { let files: Vec<String> = match matches.get_many::<String>(options::FILE) {
Some(v) => v.clone().map(|v| v.to_owned()).collect(), Some(v) => v.clone().map(|v| v.to_owned()).collect(),
None => vec!["-".to_owned()], None => vec!["-".to_owned()],
}; };

View file

@ -83,7 +83,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
modes.to_string() modes.to_string()
}; };
let mut files: Vec<String> = matches let mut files: Vec<String> = matches
.values_of(options::FILE) .get_many::<String>(options::FILE)
.map(|v| v.map(ToString::to_string).collect()) .map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default(); .unwrap_or_default();
let cmode = if fmode.is_some() { let cmode = if fmode.is_some() {

View file

@ -52,8 +52,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
return Err(ChrootError::NoSuchDirectory(format!("{}", newroot.display())).into()); return Err(ChrootError::NoSuchDirectory(format!("{}", newroot.display())).into());
} }
let commands = match matches.values_of(options::COMMAND) { let commands = match matches.get_many::<String>(options::COMMAND) {
Some(v) => v.collect(), Some(v) => v.map(|s| s.as_str()).collect(),
None => vec![], None => vec![],
}; };

View file

@ -120,7 +120,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args); let matches = uu_app().get_matches_from(args);
let files: Vec<String> = match matches.values_of(options::FILE) { let files: Vec<String> = match matches.get_many::<String>(options::FILE) {
Some(v) => v.clone().map(|v| v.to_owned()).collect(), Some(v) => v.clone().map(|v| v.to_owned()).collect(),
None => vec![], None => vec![],
}; };

View file

@ -503,7 +503,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
let paths: Vec<String> = matches let paths: Vec<String> = matches
.values_of(options::PATHS) .get_many::<String>(options::PATHS)
.map(|v| v.map(ToString::to_string).collect()) .map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default(); .unwrap_or_default();
@ -642,7 +642,7 @@ impl Options {
// Parse attributes to preserve // Parse attributes to preserve
let mut preserve_attributes: Vec<Attribute> = if matches.contains_id(options::PRESERVE) { let mut preserve_attributes: Vec<Attribute> = if matches.contains_id(options::PRESERVE) {
match matches.values_of(options::PRESERVE) { match matches.get_many::<String>(options::PRESERVE) {
None => DEFAULT_ATTRIBUTES.to_vec(), None => DEFAULT_ATTRIBUTES.to_vec(),
Some(attribute_strs) => { Some(attribute_strs) => {
let mut attributes = Vec::new(); let mut attributes = Vec::new();

View file

@ -724,9 +724,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// get the patterns to split on // get the patterns to split on
let patterns: Vec<String> = matches let patterns: Vec<String> = matches
.values_of(options::PATTERN) .get_many::<String>(options::PATTERN)
.unwrap() .unwrap()
.map(str::to_string) .map(|s| s.to_string())
.collect(); .collect();
let patterns = patterns::get_patterns(&patterns[..])?; let patterns = patterns::get_patterns(&patterns[..])?;
let options = CsplitOptions::new(&matches); let options = CsplitOptions::new(&matches);

View file

@ -523,9 +523,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}; };
let files: Vec<String> = matches let files: Vec<String> = matches
.values_of(options::FILE) .get_many::<String>(options::FILE)
.unwrap_or_default() .unwrap_or_default()
.map(str::to_owned) .map(|s| s.to_owned())
.collect(); .collect();
match mode_parse { match mode_parse {

View file

@ -156,8 +156,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let form = form[1..].to_string(); let form = form[1..].to_string();
Format::Custom(form) Format::Custom(form)
} else if let Some(fmt) = matches } else if let Some(fmt) = matches
.values_of(OPT_ISO_8601) .get_many::<String>(OPT_ISO_8601)
.map(|mut iter| iter.next().unwrap_or(DATE).into()) .map(|mut iter| iter.next().unwrap_or(&DATE.to_string()).as_str().into())
{ {
Format::Iso8601(fmt) Format::Iso8601(fmt)
} else if matches.contains_id(OPT_RFC_EMAIL) { } else if matches.contains_id(OPT_RFC_EMAIL) {

View file

@ -529,7 +529,7 @@ fn parse_flag_list<T: std::str::FromStr<Err = ParseError>>(
matches: &Matches, matches: &Matches,
) -> Result<Vec<T>, ParseError> { ) -> Result<Vec<T>, ParseError> {
matches matches
.values_of(tag) .get_many::<String>(tag)
.unwrap_or_default() .unwrap_or_default()
.map(|f| f.parse()) .map(|f| f.parse())
.collect() .collect()

View file

@ -93,7 +93,10 @@ impl Column {
// Unwrapping should not panic because in this arm of // Unwrapping should not panic because in this arm of
// the `match` statement, we know that `OPT_OUTPUT` // the `match` statement, we know that `OPT_OUTPUT`
// is non-empty. // is non-empty.
let names = matches.values_of(OPT_OUTPUT).unwrap(); let names = matches
.get_many::<String>(OPT_OUTPUT)
.unwrap()
.map(|s| s.as_str());
let mut seen: Vec<&str> = vec![]; let mut seen: Vec<&str> = vec![];
let mut columns = vec![]; let mut columns = vec![];
for name in names { for name in names {

View file

@ -442,7 +442,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let opt = Options::from(&matches).map_err(DfError::OptionsError)?; let opt = Options::from(&matches).map_err(DfError::OptionsError)?;
// Get the list of filesystems to display in the output table. // Get the list of filesystems to display in the output table.
let filesystems: Vec<Filesystem> = match matches.values_of(OPT_PATHS) { let filesystems: Vec<Filesystem> = match matches.get_many::<String>(OPT_PATHS) {
None => { None => {
let filesystems = get_all_filesystems(&opt) let filesystems = get_all_filesystems(&opt)
.map_err_context(|| "cannot read table of mounted file systems".into())?; .map_err_context(|| "cannot read table of mounted file systems".into())?;
@ -454,7 +454,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
filesystems filesystems
} }
Some(paths) => { Some(paths) => {
let paths: Vec<&str> = paths.collect(); let paths: Vec<_> = paths.collect();
let filesystems = get_named_filesystems(&paths, &opt) let filesystems = get_named_filesystems(&paths, &opt)
.map_err_context(|| "cannot read table of mounted file systems".into())?; .map_err_context(|| "cannot read table of mounted file systems".into())?;

View file

@ -72,7 +72,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(&args); let matches = uu_app().get_matches_from(&args);
let files = matches let files = matches
.values_of(options::FILE) .get_many::<String>(options::FILE)
.map_or(vec![], |file_values| file_values.collect()); .map_or(vec![], |file_values| file_values.collect());
// clap provides .conflicts_with / .conflicts_with_all, but we want to // clap provides .conflicts_with / .conflicts_with_all, but we want to

View file

@ -43,9 +43,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}; };
let dirnames: Vec<String> = matches let dirnames: Vec<String> = matches
.values_of(options::DIR) .get_many::<String>(options::DIR)
.unwrap_or_default() .unwrap_or_default()
.map(str::to_owned) .map(|s| s.to_owned())
.collect(); .collect();
if !dirnames.is_empty() { if !dirnames.is_empty() {

View file

@ -491,12 +491,12 @@ fn file_as_vec(filename: impl AsRef<Path>) -> Vec<String> {
// to ignore the files // to ignore the files
fn build_exclude_patterns(matches: &ArgMatches) -> UResult<Vec<Pattern>> { fn build_exclude_patterns(matches: &ArgMatches) -> UResult<Vec<Pattern>> {
let exclude_from_iterator = matches let exclude_from_iterator = matches
.values_of(options::EXCLUDE_FROM) .get_many::<String>(options::EXCLUDE_FROM)
.unwrap_or_default() .unwrap_or_default()
.flat_map(|f| file_as_vec(&f)); .flat_map(|f| file_as_vec(&f));
let excludes_iterator = matches let excludes_iterator = matches
.values_of(options::EXCLUDE) .get_many::<String>(options::EXCLUDE)
.unwrap_or_default() .unwrap_or_default()
.map(|v| v.to_owned()); .map(|v| v.to_owned());
@ -538,7 +538,11 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}; };
let files = match matches.value_of(options::FILE) { let files = match matches.value_of(options::FILE) {
Some(_) => matches.values_of(options::FILE).unwrap().collect(), Some(_) => matches
.get_many::<String>(options::FILE)
.unwrap()
.map(|s| s.as_str())
.collect(),
None => vec!["."], None => vec!["."],
}; };

View file

@ -117,7 +117,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let no_newline = matches.contains_id(options::NO_NEWLINE); let no_newline = matches.contains_id(options::NO_NEWLINE);
let escaped = matches.contains_id(options::ENABLE_BACKSLASH_ESCAPE); let escaped = matches.contains_id(options::ENABLE_BACKSLASH_ESCAPE);
let values: Vec<String> = match matches.values_of(options::STRING) { let values: Vec<String> = match matches.get_many::<String>(options::STRING) {
Some(s) => s.map(|s| s.to_string()).collect(), Some(s) => s.map(|s| s.to_string()).collect(),
None => vec!["".to_string()], None => vec!["".to_string()],
}; };

18
src/uu/env/src/env.rs vendored
View file

@ -178,14 +178,14 @@ fn run_env(args: impl uucore::Args) -> UResult<()> {
let ignore_env = matches.contains_id("ignore-environment"); let ignore_env = matches.contains_id("ignore-environment");
let null = matches.contains_id("null"); let null = matches.contains_id("null");
let running_directory = matches.value_of("chdir"); let running_directory = matches.value_of("chdir");
let files = matches let files = match matches.get_many::<String>("file") {
.values_of("file") Some(v) => v.map(|s| s.as_str()).collect(),
.map(Iterator::collect) None => Vec::with_capacity(0),
.unwrap_or_else(|| Vec::with_capacity(0)); };
let unsets = matches let unsets = match matches.get_many::<String>("unset") {
.values_of("unset") Some(v) => v.map(|s| s.as_str()).collect(),
.map(Iterator::collect) None => Vec::with_capacity(0),
.unwrap_or_else(|| Vec::with_capacity(0)); };
let mut opts = Options { let mut opts = Options {
ignore_env, ignore_env,
@ -222,7 +222,7 @@ fn run_env(args: impl uucore::Args) -> UResult<()> {
begin_prog_opts = parse_name_value_opt(&mut opts, external)?; begin_prog_opts = parse_name_value_opt(&mut opts, external)?;
} }
if let Some(mut iter) = matches.values_of("") { if let Some(mut iter) = matches.get_many::<String>("") {
// read NAME=VALUE arguments (and up to a single program argument) // read NAME=VALUE arguments (and up to a single program argument)
while !begin_prog_opts { while !begin_prog_opts {
if let Some(opt) = iter.next() { if let Some(opt) = iter.next() {

View file

@ -211,8 +211,8 @@ struct Options {
impl Options { impl Options {
fn new(matches: &ArgMatches) -> Result<Self, ParseError> { fn new(matches: &ArgMatches) -> Result<Self, ParseError> {
let (remaining_mode, tabstops) = match matches.values_of(options::TABS) { let (remaining_mode, tabstops) = match matches.get_many::<String>(options::TABS) {
Some(s) => tabstops_parse(&s.collect::<Vec<&str>>().join(","))?, Some(s) => tabstops_parse(&s.map(|s| s.as_str()).collect::<Vec<_>>().join(","))?,
None => (RemainingMode::None, vec![DEFAULT_TABSTOP]), None => (RemainingMode::None, vec![DEFAULT_TABSTOP]),
}; };
@ -232,7 +232,7 @@ impl Options {
.unwrap(); // length of tabstops is guaranteed >= 1 .unwrap(); // length of tabstops is guaranteed >= 1
let tspaces = " ".repeat(nspaces); let tspaces = " ".repeat(nspaces);
let files: Vec<String> = match matches.values_of(options::FILES) { let files: Vec<String> = match matches.get_many::<String>(options::FILES) {
Some(s) => s.map(|v| v.to_string()).collect(), Some(s) => s.map(|v| v.to_string()).collect(),
None => vec!["-".to_owned()], None => vec!["-".to_owned()],
}; };

View file

@ -53,7 +53,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let mut w = io::BufWriter::with_capacity(4 * 1024, stdout.lock()); let mut w = io::BufWriter::with_capacity(4 * 1024, stdout.lock());
let mut factors_buffer = String::new(); let mut factors_buffer = String::new();
if let Some(values) = matches.values_of(options::NUMBER) { if let Some(values) = matches.get_many::<String>(options::NUMBER) {
for number in values { for number in values {
if let Err(e) = print_factors_str(number, &mut w, &mut factors_buffer) { if let Err(e) = print_factors_str(number, &mut w, &mut factors_buffer) {
show_warning!("{}: {}", number.maybe_quote(), e); show_warning!("{}: {}", number.maybe_quote(), e);

View file

@ -70,7 +70,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args); let matches = uu_app().get_matches_from(args);
let mut files: Vec<String> = matches let mut files: Vec<String> = matches
.values_of(ARG_FILES) .get_many::<String>(ARG_FILES)
.map(|v| v.map(ToString::to_string).collect()) .map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default(); .unwrap_or_default();

View file

@ -55,7 +55,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
None => 80, None => 80,
}; };
let files = match matches.values_of(options::FILE) { let files = match matches.get_many::<String>(options::FILE) {
Some(v) => v.map(|v| v.to_owned()).collect(), Some(v) => v.map(|v| v.to_owned()).collect(),
None => vec!["-".to_owned()], None => vec!["-".to_owned()],
}; };

View file

@ -73,7 +73,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args); let matches = uu_app().get_matches_from(args);
let users: Vec<String> = matches let users: Vec<String> = matches
.values_of(options::USERS) .get_many::<String>(options::USERS)
.map(|v| v.map(ToString::to_string).collect()) .map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default(); .unwrap_or_default();

View file

@ -202,7 +202,7 @@ impl HeadOptions {
options.mode = Mode::from(&matches)?; options.mode = Mode::from(&matches)?;
options.files = match matches.values_of(options::FILES_NAME) { options.files = match matches.get_many::<String>(options::FILES_NAME) {
Some(v) => v.map(|s| s.to_owned()).collect(), Some(v) => v.map(|s| s.to_owned()).collect(),
None => vec!["-".to_owned()], None => vec!["-".to_owned()],
}; };

View file

@ -131,7 +131,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().after_help(&after_help[..]).get_matches_from(args); let matches = uu_app().after_help(&after_help[..]).get_matches_from(args);
let users: Vec<String> = matches let users: Vec<String> = matches
.values_of(options::ARG_USERS) .get_many::<String>(options::ARG_USERS)
.map(|v| v.map(ToString::to_string).collect()) .map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default(); .unwrap_or_default();

View file

@ -174,7 +174,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args); let matches = uu_app().get_matches_from(args);
let paths: Vec<String> = matches let paths: Vec<String> = matches
.values_of(ARG_FILES) .get_many::<String>(ARG_FILES)
.map(|v| v.map(ToString::to_string).collect()) .map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default(); .unwrap_or_default();

View file

@ -608,14 +608,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let mut settings: Settings = Default::default(); let mut settings: Settings = Default::default();
let v_values = matches.values_of("v"); let v_values = matches.get_many::<String>("v");
if v_values.is_some() { if v_values.is_some() {
settings.print_joined = false; settings.print_joined = false;
} }
let unpaired = v_values let unpaired = v_values
.unwrap_or_default() .unwrap_or_default()
.chain(matches.values_of("a").unwrap_or_default()); .chain(matches.get_many("a").unwrap_or_default());
for file_num in unpaired { for file_num in unpaired {
match parse_file_number(file_num)? { match parse_file_number(file_num)? {
FileNum::File1 => settings.print_unpaired1 = true, FileNum::File1 => settings.print_unpaired1 = true,

View file

@ -54,7 +54,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}; };
let pids_or_signals: Vec<String> = matches let pids_or_signals: Vec<String> = matches
.values_of(options::PIDS_OR_SIGNALS) .get_many::<String>(options::PIDS_OR_SIGNALS)
.map(|v| v.map(ToString::to_string).collect()) .map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default(); .unwrap_or_default();

View file

@ -141,7 +141,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
/* the list of files */ /* the list of files */
let paths: Vec<PathBuf> = matches let paths: Vec<PathBuf> = matches
.values_of(ARG_FILES) .get_many::<String>(ARG_FILES)
.unwrap() .unwrap()
.map(PathBuf::from) .map(PathBuf::from)
.collect(); .collect();

View file

@ -730,7 +730,11 @@ impl Config {
ignore_patterns.push(Pattern::new(".*~").unwrap()); ignore_patterns.push(Pattern::new(".*~").unwrap());
} }
for pattern in options.values_of(options::IGNORE).into_iter().flatten() { for pattern in options
.get_many::<String>(options::IGNORE)
.into_iter()
.flatten()
{
match Pattern::new(pattern) { match Pattern::new(pattern) {
Ok(p) => { Ok(p) => {
ignore_patterns.push(p); ignore_patterns.push(p);
@ -740,7 +744,11 @@ impl Config {
} }
if files == Files::Normal { if files == Files::Normal {
for pattern in options.values_of(options::HIDE).into_iter().flatten() { for pattern in options
.get_many::<String>(options::HIDE)
.into_iter()
.flatten()
{
match Pattern::new(pattern) { match Pattern::new(pattern) {
Ok(p) => { Ok(p) => {
ignore_patterns.push(p); ignore_patterns.push(p);

View file

@ -49,7 +49,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
None => 0o666, None => 0o666,
}; };
let fifos: Vec<String> = match matches.values_of(options::FIFO) { let fifos: Vec<String> = match matches.get_many::<String>(options::FIFO) {
Some(v) => v.clone().map(|s| s.to_owned()).collect(), Some(v) => v.clone().map(|s| s.to_owned()).collect(),
None => return Err(USimpleError::new(1, "missing operand")), None => return Err(USimpleError::new(1, "missing operand")),
}; };

View file

@ -55,11 +55,11 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let mut buff = String::new(); let mut buff = String::new();
let silent = matches.contains_id(options::SILENT); let silent = matches.contains_id(options::SILENT);
if let Some(files) = matches.values_of(options::FILES) { if let Some(files) = matches.get_many::<String>(options::FILES) {
let mut stdout = setup_term(); let mut stdout = setup_term();
let length = files.len(); let length = files.len();
let mut files_iter = files.peekable(); let mut files_iter = files.map(|s| s.as_str()).peekable();
while let (Some(file), next_file) = (files_iter.next(), files_iter.peek()) { while let (Some(file), next_file) = (files_iter.next(), files_iter.peek()) {
let file = Path::new(file); let file = Path::new(file);
if file.is_dir() { if file.is_dir() {

View file

@ -79,7 +79,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
let cstrs: Vec<CString> = matches let cstrs: Vec<CString> = matches
.values_of(options::COMMAND) .get_many::<String>(options::COMMAND)
.unwrap() .unwrap()
.map(|x| CString::new(x.as_bytes()).unwrap()) .map(|x| CString::new(x.as_bytes()).unwrap())
.collect(); .collect();

View file

@ -116,7 +116,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
let mut read_stdin = false; let mut read_stdin = false;
let files: Vec<String> = match matches.values_of(options::FILE) { let files: Vec<String> = match matches.get_many::<String>(options::FILE) {
Some(v) => v.clone().map(|v| v.to_owned()).collect(), Some(v) => v.clone().map(|v| v.to_owned()).collect(),
None => vec!["-".to_owned()], None => vec!["-".to_owned()],
}; };

View file

@ -101,7 +101,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}; };
let cstrs: Vec<CString> = matches let cstrs: Vec<CString> = matches
.values_of(options::CMD) .get_many::<String>(options::CMD)
.unwrap() .unwrap()
.map(|x| CString::new(x.as_bytes()).unwrap()) .map(|x| CString::new(x.as_bytes()).unwrap())
.collect(); .collect();

View file

@ -269,8 +269,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let options = parse_options(&matches).map_err(NumfmtError::IllegalArgument)?; let options = parse_options(&matches).map_err(NumfmtError::IllegalArgument)?;
let result = match matches.values_of(options::NUMBER) { let result = match matches.get_many::<String>(options::NUMBER) {
Some(values) => handle_args(values, &options), Some(values) => handle_args(values.map(|s| s.as_str()), &options),
None => { None => {
let stdin = std::io::stdin(); let stdin = std::io::stdin();
let mut locked_stdin = stdin.lock(); let mut locked_stdin = stdin.lock();

View file

@ -12,8 +12,8 @@ pub trait CommandLineOpts {
/// Implementation for `getopts` /// Implementation for `getopts`
impl CommandLineOpts for ArgMatches { impl CommandLineOpts for ArgMatches {
fn inputs(&self) -> Vec<&str> { fn inputs(&self) -> Vec<&str> {
self.values_of(options::FILENAME) self.get_many::<String>(options::FILENAME)
.map(|values| values.collect()) .map(|values| values.map(|s| s.as_str()).collect())
.unwrap_or_default() .unwrap_or_default()
} }

View file

@ -59,7 +59,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let serial = matches.contains_id(options::SERIAL); let serial = matches.contains_id(options::SERIAL);
let delimiters = matches.value_of(options::DELIMITER).unwrap(); let delimiters = matches.value_of(options::DELIMITER).unwrap();
let files = matches let files = matches
.values_of(options::FILE) .get_many::<String>(options::FILE)
.unwrap() .unwrap()
.map(|s| s.to_owned()) .map(|s| s.to_owned())
.collect(); .collect();

View file

@ -46,9 +46,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args); let matches = uu_app().get_matches_from(args);
// set working mode // set working mode
let is_posix = matches.values_of(options::POSIX).is_some(); let is_posix = matches.get_many::<String>(options::POSIX).is_some();
let is_posix_special = matches.values_of(options::POSIX_SPECIAL).is_some(); let is_posix_special = matches.get_many::<String>(options::POSIX_SPECIAL).is_some();
let is_portability = matches.values_of(options::PORTABILITY).is_some(); let is_portability = matches.get_many::<String>(options::PORTABILITY).is_some();
let mode = if (is_posix && is_posix_special) || is_portability { let mode = if (is_posix && is_posix_special) || is_portability {
Mode::Both Mode::Both
@ -61,7 +61,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}; };
// take necessary actions // take necessary actions
let paths = matches.values_of(options::PATH); let paths = matches.get_many::<String>(options::PATH);
if paths.is_none() { if paths.is_none() {
return Err(UUsageError::new(1, "missing operand")); return Err(UUsageError::new(1, "missing operand"));
} }

View file

@ -58,7 +58,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().after_help(&after_help[..]).get_matches_from(args); let matches = uu_app().after_help(&after_help[..]).get_matches_from(args);
let users: Vec<String> = matches let users: Vec<String> = matches
.values_of(options::USER) .get_many::<String>(options::USER)
.map(|v| v.map(ToString::to_string).collect()) .map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default(); .unwrap_or_default();

View file

@ -405,8 +405,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
let mut files = matches let mut files = matches
.values_of(options::FILES) .get_many::<String>(options::FILES)
.map(|v| v.collect::<Vec<_>>()) .map(|v| v.map(|s| s.as_str()).collect::<Vec<_>>())
.unwrap_or_default() .unwrap_or_default()
.clone(); .clone();
if files.is_empty() { if files.is_empty() {

View file

@ -23,7 +23,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args); let matches = uu_app().get_matches_from(args);
let variables: Vec<String> = matches let variables: Vec<String> = matches
.values_of(ARG_VARIABLES) .get_many::<String>(ARG_VARIABLES)
.map(|v| v.map(ToString::to_string).collect()) .map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default(); .unwrap_or_default();

View file

@ -279,7 +279,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let format_string = matches let format_string = matches
.value_of(options::FORMATSTRING) .value_of(options::FORMATSTRING)
.ok_or_else(|| UUsageError::new(1, "missing operand"))?; .ok_or_else(|| UUsageError::new(1, "missing operand"))?;
let values: Vec<String> = match matches.values_of(options::ARGUMENT) { let values: Vec<String> = match matches.get_many::<String>(options::ARGUMENT) {
Some(s) => s.map(|s| s.to_string()).collect(), Some(s) => s.map(|s| s.to_string()).collect(),
None => vec![], None => vec![],
}; };

View file

@ -729,7 +729,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// let mut opts = Options::new(); // let mut opts = Options::new();
let matches = uu_app().get_matches_from(args); let matches = uu_app().get_matches_from(args);
let mut input_files: Vec<String> = match &matches.values_of(options::FILE) { let mut input_files: Vec<String> = match &matches.get_many::<String>(options::FILE) {
Some(v) => v.clone().map(|v| v.to_owned()).collect(), Some(v) => v.clone().map(|v| v.to_owned()).collect(),
None => vec!["-".to_string()], None => vec!["-".to_string()],
}; };

View file

@ -59,7 +59,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}; };
let files: Vec<String> = matches let files: Vec<String> = matches
.values_of(ARG_FILES) .get_many::<String>(ARG_FILES)
.map(|v| v.map(ToString::to_string).collect()) .map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default(); .unwrap_or_default();
if files.is_empty() { if files.is_empty() {

View file

@ -46,7 +46,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
/* the list of files */ /* the list of files */
let paths: Vec<PathBuf> = matches let paths: Vec<PathBuf> = matches
.values_of(ARG_FILES) .get_many::<String>(ARG_FILES)
.unwrap() .unwrap()
.map(PathBuf::from) .map(PathBuf::from)
.collect(); .collect();

View file

@ -81,7 +81,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().after_help(&long_usage[..]).get_matches_from(args); let matches = uu_app().after_help(&long_usage[..]).get_matches_from(args);
let files: Vec<String> = matches let files: Vec<String> = matches
.values_of(ARG_FILES) .get_many::<String>(ARG_FILES)
.map(|v| v.map(ToString::to_string).collect()) .map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default(); .unwrap_or_default();

View file

@ -61,7 +61,10 @@ type RangeFloat = (ExtendedBigDecimal, ExtendedBigDecimal, ExtendedBigDecimal);
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args); let matches = uu_app().get_matches_from(args);
let numbers = matches.values_of(ARG_NUMBERS).unwrap().collect::<Vec<_>>(); let numbers = matches
.get_many::<String>(ARG_NUMBERS)
.unwrap()
.collect::<Vec<_>>();
let options = SeqOptions { let options = SeqOptions {
separator: matches.value_of(OPT_SEPARATOR).unwrap_or("\n").to_string(), separator: matches.value_of(OPT_SEPARATOR).unwrap_or("\n").to_string(),

View file

@ -306,7 +306,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let zero = matches.contains_id(options::ZERO); let zero = matches.contains_id(options::ZERO);
let verbose = matches.contains_id(options::VERBOSE); let verbose = matches.contains_id(options::VERBOSE);
for path_str in matches.values_of(options::FILE).unwrap() { for path_str in matches.get_many::<String>(options::FILE).unwrap() {
show_if_err!(wipe_file( show_if_err!(wipe_file(
path_str, iterations, remove, size, exact, zero, verbose, force, path_str, iterations, remove, size, exact, zero, verbose, force,
)); ));

View file

@ -7,7 +7,7 @@
// spell-checker:ignore (ToDO) cmdline evec seps rvec fdata // spell-checker:ignore (ToDO) cmdline evec seps rvec fdata
use clap::{crate_version, Arg, Command, Values}; use clap::{crate_version, Arg, Command};
use memchr::memchr_iter; use memchr::memchr_iter;
use rand::prelude::SliceRandom; use rand::prelude::SliceRandom;
use rand::RngCore; use rand::RngCore;
@ -62,7 +62,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args); let matches = uu_app().get_matches_from(args);
let mode = if let Some(args) = matches.values_of(options::ECHO) { let mode = if let Some(args) = matches.get_many::<String>(options::ECHO) {
Mode::Echo(args.map(String::from).collect()) Mode::Echo(args.map(String::from).collect())
} else if let Some(range) = matches.value_of(options::INPUT_RANGE) { } else if let Some(range) = matches.value_of(options::INPUT_RANGE) {
match parse_range(range) { match parse_range(range) {
@ -77,9 +77,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let options = Options { let options = Options {
head_count: { head_count: {
let mut headcounts: Values<'_> = let headcounts = matches
matches.values_of(options::HEAD_COUNT).unwrap_or_default(); .get_many::<String>(options::HEAD_COUNT)
match parse_head_count(&mut headcounts) { .unwrap_or_default()
.map(|s| s.to_owned())
.collect();
match parse_head_count(headcounts) {
Ok(val) => val, Ok(val) => val,
Err(msg) => return Err(USimpleError::new(1, msg)), Err(msg) => return Err(USimpleError::new(1, msg)),
} }
@ -295,7 +298,7 @@ fn parse_range(input_range: &str) -> Result<(usize, usize), String> {
} }
} }
fn parse_head_count(headcounts: &mut Values<'_>) -> Result<usize, String> { fn parse_head_count(headcounts: Vec<String>) -> Result<usize, String> {
let mut result = std::usize::MAX; let mut result = std::usize::MAX;
for count in headcounts { for count in headcounts {
match count.parse::<usize>() { match count.parse::<usize>() {

View file

@ -33,8 +33,8 @@ mod options {
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(args)?; let matches = uu_app().try_get_matches_from(args)?;
if let Some(values) = matches.values_of(options::NUMBER) { if let Some(values) = matches.get_many::<String>(options::NUMBER) {
let numbers = values.collect::<Vec<_>>(); let numbers = values.map(|s| s.as_str()).collect::<Vec<_>>();
return sleep(&numbers); return sleep(&numbers);
} }

View file

@ -1228,7 +1228,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
settings.separator = Some(separator.chars().next().unwrap()); settings.separator = Some(separator.chars().next().unwrap());
} }
if let Some(values) = matches.values_of(options::KEY) { if let Some(values) = matches.get_many::<String>(options::KEY) {
for value in values { for value in values {
let selector = FieldSelector::parse(value, &settings)?; let selector = FieldSelector::parse(value, &settings)?;
if selector.settings.mode == SortMode::Random && settings.salt.is_none() { if selector.settings.mode == SortMode::Random && settings.salt.is_none() {

View file

@ -115,7 +115,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args); let matches = uu_app().get_matches_from(args);
let files: Vec<String> = match matches.values_of(options::FILE) { let files: Vec<String> = match matches.get_many::<String>(options::FILE) {
Some(v) => v.clone().map(|v| v.to_owned()).collect(), Some(v) => v.clone().map(|v| v.to_owned()).collect(),
None => vec!["-".to_owned()], None => vec!["-".to_owned()],
}; };

View file

@ -168,7 +168,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args); let matches = uu_app().get_matches_from(args);
let files: Vec<String> = matches let files: Vec<String> = matches
.values_of(ARG_FILES) .get_many::<String>(ARG_FILES)
.map(|v| v.map(ToString::to_string).collect()) .map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default(); .unwrap_or_default();

View file

@ -52,8 +52,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
raw_separator raw_separator
}; };
let files: Vec<&str> = match matches.values_of(options::FILE) { let files: Vec<&str> = match matches.get_many::<String>(options::FILE) {
Some(v) => v.collect(), Some(v) => v.map(|s| s.as_str()).collect(),
None => vec!["-"], None => vec!["-"],
}; };

View file

@ -264,7 +264,7 @@ impl Settings {
settings.stdin_is_pipe_or_fifo = matches.contains_id(options::PRESUME_INPUT_PIPE); settings.stdin_is_pipe_or_fifo = matches.contains_id(options::PRESUME_INPUT_PIPE);
settings.paths = matches settings.paths = matches
.values_of(options::ARG_FILES) .get_many::<String>(options::ARG_FILES)
.map(|v| v.map(PathBuf::from).collect()) .map(|v| v.map(PathBuf::from).collect())
.unwrap_or_default(); .unwrap_or_default();

View file

@ -57,7 +57,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
append: matches.contains_id(options::APPEND), append: matches.contains_id(options::APPEND),
ignore_interrupts: matches.contains_id(options::IGNORE_INTERRUPTS), ignore_interrupts: matches.contains_id(options::IGNORE_INTERRUPTS),
files: matches files: matches
.values_of(options::FILE) .get_many::<String>(options::FILE)
.map(|v| v.map(ToString::to_string).collect()) .map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default(), .unwrap_or_default(),
output_error: { output_error: {

View file

@ -87,7 +87,7 @@ impl Config {
let verbose = options.contains_id(options::VERBOSE); let verbose = options.contains_id(options::VERBOSE);
let command = options let command = options
.values_of(options::COMMAND) .get_many::<String>(options::COMMAND)
.unwrap() .unwrap()
.map(String::from) .map(String::from)
.collect::<Vec<_>>(); .collect::<Vec<_>>();

View file

@ -54,7 +54,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let truncate_set1_flag = matches.contains_id(options::TRUNCATE_SET1); let truncate_set1_flag = matches.contains_id(options::TRUNCATE_SET1);
let sets = matches let sets = matches
.values_of(options::SETS) .get_many::<String>(options::SETS)
.map(|v| { .map(|v| {
v.map(ToString::to_string) v.map(ToString::to_string)
.map(|input| convert::reduce_octal_to_char(&input)) .map(|input| convert::reduce_octal_to_char(&input))

View file

@ -122,7 +122,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
})?; })?;
let files: Vec<String> = matches let files: Vec<String> = matches
.values_of(options::ARG_FILES) .get_many::<String>(options::ARG_FILES)
.map(|v| v.map(ToString::to_string).collect()) .map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default(); .unwrap_or_default();

View file

@ -104,9 +104,9 @@ struct Options {
impl Options { impl Options {
fn new(matches: &clap::ArgMatches) -> Result<Self, ParseError> { fn new(matches: &clap::ArgMatches) -> Result<Self, ParseError> {
let tabstops = match matches.values_of(options::TABS) { let tabstops = match matches.get_many::<String>(options::TABS) {
None => vec![DEFAULT_TABSTOP], None => vec![DEFAULT_TABSTOP],
Some(s) => tabstops_parse(&s.collect::<Vec<&str>>().join(","))?, Some(s) => tabstops_parse(&s.map(|s| s.as_str()).collect::<Vec<_>>().join(","))?,
}; };
let aflag = (matches.contains_id(options::ALL) || matches.contains_id(options::TABS)) let aflag = (matches.contains_id(options::ALL) || matches.contains_id(options::TABS))

View file

@ -260,7 +260,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().after_help(&long_usage[..]).get_matches_from(args); let matches = uu_app().after_help(&long_usage[..]).get_matches_from(args);
let files: Vec<String> = matches let files: Vec<String> = matches
.values_of(ARG_FILES) .get_many::<String>(ARG_FILES)
.map(|v| v.map(ToString::to_string).collect()) .map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default(); .unwrap_or_default();

View file

@ -65,7 +65,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().after_help(&after_help[..]).get_matches_from(args); let matches = uu_app().after_help(&after_help[..]).get_matches_from(args);
let files: Vec<String> = matches let files: Vec<String> = matches
.values_of(options::FILE) .get_many::<String>(options::FILE)
.map(|v| v.map(ToString::to_string).collect()) .map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default(); .unwrap_or_default();

View file

@ -28,7 +28,7 @@ const BUF_SIZE: usize = 16 * 1024;
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args); let matches = uu_app().get_matches_from(args);
let string = if let Some(values) = matches.values_of("STRING") { let string = if let Some(values) = matches.get_many::<String>("STRING") {
let mut result = values.fold(String::new(), |res, s| res + s + " "); let mut result = values.fold(String::new(), |res, s| res + s + " ");
result.pop(); result.pop();
result.push('\n'); result.push('\n');

View file

@ -466,7 +466,7 @@ pub fn chown_base<'a>(
let matches = command.get_matches_from(args); let matches = command.get_matches_from(args);
let files: Vec<String> = matches let files: Vec<String> = matches
.values_of(options::ARG_FILES) .get_many::<String>(options::ARG_FILES)
.map(|v| v.map(ToString::to_string).collect()) .map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default(); .unwrap_or_default();