Skip to content

Commit

Permalink
Merge pull request #3804 from cakebaker/clap_replace_deprecated_value…
Browse files Browse the repository at this point in the history
…s_of

Replace deprecated values_of() with get_many()
  • Loading branch information
sylvestre authored Aug 11, 2022
2 parents a27e011 + c0c26c4 commit 0f1b98c
Show file tree
Hide file tree
Showing 65 changed files with 133 additions and 104 deletions.
2 changes: 1 addition & 1 deletion src/uu/base32/src/base_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub mod options {

impl Config {
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) => {
let name = values.next().unwrap();
if let Some(extra_op) = values.next() {
Expand Down
16 changes: 12 additions & 4 deletions src/uu/basename/src/basename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
format!(
"extra operand {}",
matches
.values_of(options::NAME)
.get_many::<String>(options::NAME)
.unwrap()
.nth(2)
.unwrap()
Expand All @@ -81,7 +81,11 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let suffix = if opt_suffix {
matches.value_of(options::SUFFIX).unwrap()
} 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 {
""
};
Expand All @@ -91,9 +95,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
//

let paths: Vec<_> = if multiple_paths {
matches.values_of(options::NAME).unwrap().collect()
matches.get_many::<String>(options::NAME).unwrap().collect()
} 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" };
Expand Down
2 changes: 1 addition & 1 deletion src/uu/cat/src/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.any(|v| matches.contains_id(v));

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(),
None => vec!["-".to_owned()],
};
Expand Down
2 changes: 1 addition & 1 deletion src/uu/chmod/src/chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
modes.to_string()
};
let mut files: Vec<String> = matches
.values_of(options::FILE)
.get_many::<String>(options::FILE)
.map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default();
let cmode = if fmode.is_some() {
Expand Down
4 changes: 2 additions & 2 deletions src/uu/chroot/src/chroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
return Err(ChrootError::NoSuchDirectory(format!("{}", newroot.display())).into());
}

let commands = match matches.values_of(options::COMMAND) {
Some(v) => v.collect(),
let commands = match matches.get_many::<String>(options::COMMAND) {
Some(v) => v.map(|s| s.as_str()).collect(),
None => vec![],
};

Expand Down
2 changes: 1 addition & 1 deletion src/uu/cksum/src/cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {

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(),
None => vec![],
};
Expand Down
4 changes: 2 additions & 2 deletions src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}

let paths: Vec<String> = matches
.values_of(options::PATHS)
.get_many::<String>(options::PATHS)
.map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default();

Expand Down Expand Up @@ -642,7 +642,7 @@ impl Options {

// Parse attributes to 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(),
Some(attribute_strs) => {
let mut attributes = Vec::new();
Expand Down
4 changes: 2 additions & 2 deletions src/uu/csplit/src/csplit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,9 +724,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {

// get the patterns to split on
let patterns: Vec<String> = matches
.values_of(options::PATTERN)
.get_many::<String>(options::PATTERN)
.unwrap()
.map(str::to_string)
.map(|s| s.to_string())
.collect();
let patterns = patterns::get_patterns(&patterns[..])?;
let options = CsplitOptions::new(&matches);
Expand Down
4 changes: 2 additions & 2 deletions src/uu/cut/src/cut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
};

let files: Vec<String> = matches
.values_of(options::FILE)
.get_many::<String>(options::FILE)
.unwrap_or_default()
.map(str::to_owned)
.map(|s| s.to_owned())
.collect();

match mode_parse {
Expand Down
4 changes: 2 additions & 2 deletions src/uu/date/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let form = form[1..].to_string();
Format::Custom(form)
} else if let Some(fmt) = matches
.values_of(OPT_ISO_8601)
.map(|mut iter| iter.next().unwrap_or(DATE).into())
.get_many::<String>(OPT_ISO_8601)
.map(|mut iter| iter.next().unwrap_or(&DATE.to_string()).as_str().into())
{
Format::Iso8601(fmt)
} else if matches.contains_id(OPT_RFC_EMAIL) {
Expand Down
2 changes: 1 addition & 1 deletion src/uu/dd/src/parseargs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ fn parse_flag_list<T: std::str::FromStr<Err = ParseError>>(
matches: &Matches,
) -> Result<Vec<T>, ParseError> {
matches
.values_of(tag)
.get_many::<String>(tag)
.unwrap_or_default()
.map(|f| f.parse())
.collect()
Expand Down
5 changes: 4 additions & 1 deletion src/uu/df/src/columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ impl Column {
// Unwrapping should not panic because in this arm of
// the `match` statement, we know that `OPT_OUTPUT`
// 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 columns = vec![];
for name in names {
Expand Down
4 changes: 2 additions & 2 deletions src/uu/df/src/df.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {

let opt = Options::from(&matches).map_err(DfError::OptionsError)?;
// 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 => {
let filesystems = get_all_filesystems(&opt)
.map_err_context(|| "cannot read table of mounted file systems".into())?;
Expand All @@ -454,7 +454,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
filesystems
}
Some(paths) => {
let paths: Vec<&str> = paths.collect();
let paths: Vec<_> = paths.collect();
let filesystems = get_named_filesystems(&paths, &opt)
.map_err_context(|| "cannot read table of mounted file systems".into())?;

Expand Down
2 changes: 1 addition & 1 deletion src/uu/dircolors/src/dircolors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(&args);

let files = matches
.values_of(options::FILE)
.get_many::<String>(options::FILE)
.map_or(vec![], |file_values| file_values.collect());

// clap provides .conflicts_with / .conflicts_with_all, but we want to
Expand Down
4 changes: 2 additions & 2 deletions src/uu/dirname/src/dirname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
};

let dirnames: Vec<String> = matches
.values_of(options::DIR)
.get_many::<String>(options::DIR)
.unwrap_or_default()
.map(str::to_owned)
.map(|s| s.to_owned())
.collect();

if !dirnames.is_empty() {
Expand Down
10 changes: 7 additions & 3 deletions src/uu/du/src/du.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,12 @@ fn file_as_vec(filename: impl AsRef<Path>) -> Vec<String> {
// to ignore the files
fn build_exclude_patterns(matches: &ArgMatches) -> UResult<Vec<Pattern>> {
let exclude_from_iterator = matches
.values_of(options::EXCLUDE_FROM)
.get_many::<String>(options::EXCLUDE_FROM)
.unwrap_or_default()
.flat_map(|f| file_as_vec(&f));

let excludes_iterator = matches
.values_of(options::EXCLUDE)
.get_many::<String>(options::EXCLUDE)
.unwrap_or_default()
.map(|v| v.to_owned());

Expand Down Expand Up @@ -538,7 +538,11 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
};

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!["."],
};

Expand Down
2 changes: 1 addition & 1 deletion src/uu/echo/src/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {

let no_newline = matches.contains_id(options::NO_NEWLINE);
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(),
None => vec!["".to_string()],
};
Expand Down
18 changes: 9 additions & 9 deletions src/uu/env/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ fn run_env(args: impl uucore::Args) -> UResult<()> {
let ignore_env = matches.contains_id("ignore-environment");
let null = matches.contains_id("null");
let running_directory = matches.value_of("chdir");
let files = matches
.values_of("file")
.map(Iterator::collect)
.unwrap_or_else(|| Vec::with_capacity(0));
let unsets = matches
.values_of("unset")
.map(Iterator::collect)
.unwrap_or_else(|| Vec::with_capacity(0));
let files = match matches.get_many::<String>("file") {
Some(v) => v.map(|s| s.as_str()).collect(),
None => Vec::with_capacity(0),
};
let unsets = match matches.get_many::<String>("unset") {
Some(v) => v.map(|s| s.as_str()).collect(),
None => Vec::with_capacity(0),
};

let mut opts = Options {
ignore_env,
Expand Down Expand Up @@ -222,7 +222,7 @@ fn run_env(args: impl uucore::Args) -> UResult<()> {
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)
while !begin_prog_opts {
if let Some(opt) = iter.next() {
Expand Down
6 changes: 3 additions & 3 deletions src/uu/expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ struct Options {

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

Expand All @@ -232,7 +232,7 @@ impl Options {
.unwrap(); // length of tabstops is guaranteed >= 1
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(),
None => vec!["-".to_owned()],
};
Expand Down
2 changes: 1 addition & 1 deletion src/uu/factor/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 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 {
if let Err(e) = print_factors_str(number, &mut w, &mut factors_buffer) {
show_warning!("{}: {}", number.maybe_quote(), e);
Expand Down
2 changes: 1 addition & 1 deletion src/uu/fmt/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);

let mut files: Vec<String> = matches
.values_of(ARG_FILES)
.get_many::<String>(ARG_FILES)
.map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default();

Expand Down
2 changes: 1 addition & 1 deletion src/uu/fold/src/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
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(),
None => vec!["-".to_owned()],
};
Expand Down
2 changes: 1 addition & 1 deletion src/uu/groups/src/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);

let users: Vec<String> = matches
.values_of(options::USERS)
.get_many::<String>(options::USERS)
.map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default();

Expand Down
2 changes: 1 addition & 1 deletion src/uu/head/src/head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl HeadOptions {

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(),
None => vec!["-".to_owned()],
};
Expand Down
2 changes: 1 addition & 1 deletion src/uu/id/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 users: Vec<String> = matches
.values_of(options::ARG_USERS)
.get_many::<String>(options::ARG_USERS)
.map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default();

Expand Down
2 changes: 1 addition & 1 deletion src/uu/install/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);

let paths: Vec<String> = matches
.values_of(ARG_FILES)
.get_many::<String>(ARG_FILES)
.map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default();

Expand Down
4 changes: 2 additions & 2 deletions src/uu/join/src/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,14 +608,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {

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() {
settings.print_joined = false;
}

let unpaired = v_values
.unwrap_or_default()
.chain(matches.values_of("a").unwrap_or_default());
.chain(matches.get_many("a").unwrap_or_default());
for file_num in unpaired {
match parse_file_number(file_num)? {
FileNum::File1 => settings.print_unpaired1 = true,
Expand Down
2 changes: 1 addition & 1 deletion src/uu/kill/src/kill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
};

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())
.unwrap_or_default();

Expand Down
2 changes: 1 addition & 1 deletion src/uu/ln/src/ln.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
/* the list of files */

let paths: Vec<PathBuf> = matches
.values_of(ARG_FILES)
.get_many::<String>(ARG_FILES)
.unwrap()
.map(PathBuf::from)
.collect();
Expand Down
Loading

0 comments on commit 0f1b98c

Please sign in to comment.