depr(Arg.rs): adds deprecations in prep for v3

A full list of deprecations is:

* Arg::last -> ArgSettings::Last
* Arg::required -> ArgSettings::Required
* Arg::require_equals -> ArgSettings::RequireEquals
* Arg::allow_hyphen_values -> ArgSettings::AllowHyphenValues
* Arg::takes_value -> ArgSettings::TakesValue
* Arg::hide_possible_values -> ArgSettings::HidePossibleValues
* Arg::hide_default_value -> ArgSettings::HideDefaultValue
* Arg::multiple -> ArgSettings::Multiple (see Arg::multiple split)
* Arg::multiple -> ArgSettings::MultipleValues (see Arg::multiple split)
* Arg::multiple -> ArgSettings::MultipleOccurrences (see Arg::multiple split)
* Arg::global -> ArgSettings::Global
* Arg::empty_values -> ArgSettings::AllowEmptyValues
* Arg::hidden -> ArgSettings::Hidden
* Arg::case_insensitive -> ArgSettings::IgnoreCase
* Arg::use_delimiter -> ArgSettings::UseDelimiter
* Arg::require_delimiter -> ArgSettings::RequireDelimiter
* Arg::hide_env_values -> ArgSettings::HideEnvValues
* Arg::next_line_help -> ArgSettings::NextLineHelp
* Arg::set -> Arg::unset_setting (consistent naming with App)
* Arg::unset -> Arg::setting (consistent naming with App)

Relates to #1037
This commit is contained in:
Kevin K 2018-01-30 21:57:29 -05:00
parent e1f1b474a3
commit 6fc70d825c
No known key found for this signature in database
GPG key ID: 17218E4B3692F01A
14 changed files with 1887 additions and 1580 deletions

View file

@ -296,6 +296,8 @@ impl<'w> Help<'w> {
/// Writes argument's possible values to the wrapped stream.
fn val<'b, 'c>(&mut self, arg: &Arg<'b, 'c>) -> Result<String, io::Error> {
debugln!("Help::val: arg={}", arg.name);
let mult =
arg.is_set(ArgSettings::MultipleValues) || arg.is_set(ArgSettings::MultipleOccurrences);
if arg.is_set(ArgSettings::TakesValue) {
let delim = if arg.is_set(ArgSettings::RequireDelimiter) {
arg.val_delim.expect(INTERNAL_ERROR_MSG)
@ -311,7 +313,7 @@ impl<'w> Help<'w> {
}
}
let num = vec.len();
if arg.is_set(ArgSettings::Multiple) && num == 1 {
if mult && num == 1 {
color!(self, "...", good)?;
}
} else if let Some(num) = arg.num_vals {
@ -322,12 +324,12 @@ impl<'w> Help<'w> {
write!(self.writer, "{}", delim)?;
}
}
if arg.is_set(ArgSettings::Multiple) && num == 1 {
if mult && num == 1 {
color!(self, "...", good)?;
}
} else if arg.has_switch() {
color!(self, "<{}>", arg.name, good)?;
if arg.is_set(ArgSettings::Multiple) {
if mult {
color!(self, "...", good)?;
}
} else {

View file

@ -1564,8 +1564,8 @@ impl<'a, 'b> App<'a, 'b> {
assert!(
positionals!(self).fold(0, |acc, p| if p.index == Some(idx as u64){acc+1}else{acc}) < 2,
"Argument '{}' has the same index as another positional \
argument\n\n\tUse Arg::multiple(true) to allow one positional argument \
to take multiple values",
argument\n\n\tUse Arg::setting(ArgSettings::MultipleValues) to allow one \
positional argument to take multiple values",
a.name
);
}

View file

@ -128,7 +128,7 @@ where
// Next we verify that only the highest index has a .multiple(true) (if any)
if positionals!(self.app).any(|a| {
a.is_set(ArgSettings::Multiple) && (a.index.unwrap_or(0) != highest_idx as u64)
a.is_set(ArgSettings::MultipleValues) && (a.index.unwrap_or(0) != highest_idx as u64)
}) {
// First we make sure if there is a positional that allows multiple values
// the one before it (second to last) has one of these:
@ -157,7 +157,8 @@ where
);
// We make sure if the second to last is Multiple the last is ArgSettings::Last
let ok = second_to_last.is_set(ArgSettings::Multiple) || last.is_set(ArgSettings::Last);
let ok = second_to_last.is_set(ArgSettings::MultipleValues)
|| last.is_set(ArgSettings::Last);
assert!(
ok,
"Only the last positional argument, or second to last positional \
@ -166,15 +167,15 @@ where
// Next we check how many have both Multiple and not a specific number of values set
let count = positionals!(self.app).fold(0, |acc, p| {
if p.settings.is_set(ArgSettings::Multiple) && p.num_vals.is_none() {
if p.settings.is_set(ArgSettings::MultipleValues) && p.num_vals.is_none() {
acc + 1
} else {
acc
}
});
let ok = count <= 1
|| (last.is_set(ArgSettings::Last) && last.is_set(ArgSettings::Multiple)
&& second_to_last.is_set(ArgSettings::Multiple)
|| (last.is_set(ArgSettings::Last) && last.is_set(ArgSettings::MultipleValues)
&& second_to_last.is_set(ArgSettings::MultipleValues)
&& count == 2);
assert!(
ok,
@ -307,7 +308,7 @@ where
debug_assert!(self._verify_positionals());
// Set the LowIndexMultiple flag if required
if positionals!(self.app).any(|a| {
a.is_set(ArgSettings::Multiple)
a.is_set(ArgSettings::MultipleValues)
&& (a.index.unwrap_or(0) as usize != self.positionals.len())
}) && self.positionals.values().last().map_or(false, |p_name| {
!find!(self.app, p_name)
@ -535,7 +536,7 @@ where
self.app.settings.set(AS::ValidArgFound);
// Only increment the positional counter if it doesn't allow multiples
if !p.settings.is_set(ArgSettings::Multiple) {
if !p.settings.is_set(ArgSettings::MultipleValues) {
pos_counter += 1;
}
self.app.settings.set(AS::ValidArgFound);
@ -721,7 +722,7 @@ where
if help_help {
let mut pb = Arg::with_name("subcommand")
.index(1)
.set(ArgSettings::Multiple)
.setting(ArgSettings::MultipleValues)
.help("The subcommand whose help message to display");
pb._build();
parser.positionals.insert(1, pb.name);
@ -754,11 +755,11 @@ where
let arg_allows_tac = match needs_val_of {
ParseResult::Opt(name) => {
let o = find!(self.app, &name).expect(INTERNAL_ERROR_MSG);
(o.is_set(ArgSettings::AllowLeadingHyphen) || app_wide_settings)
(o.is_set(ArgSettings::AllowHyphenValues) || app_wide_settings)
}
ParseResult::Pos(name) => {
let p = find!(self.app, &name).expect(INTERNAL_ERROR_MSG);
(p.is_set(ArgSettings::AllowLeadingHyphen) || app_wide_settings)
(p.is_set(ArgSettings::AllowHyphenValues) || app_wide_settings)
}
ParseResult::ValuesDone => return true,
_ => false,
@ -1061,7 +1062,7 @@ where
debugln!("Parser::parse_opt; opt.settings={:?}", opt.settings);
let mut has_eq = false;
let no_val = val.is_none();
let empty_vals = opt.is_set(ArgSettings::EmptyValues);
let empty_vals = opt.is_set(ArgSettings::AllowEmptyValues);
let min_vals_zero = opt.min_vals.unwrap_or(1) == 0;
let needs_eq = opt.is_set(ArgSettings::RequireEquals);
@ -1101,7 +1102,8 @@ where
.and_then(|vec| Some(matcher.inc_occurrences_of(&*vec)));
let needs_delim = opt.is_set(ArgSettings::RequireDelimiter);
let mult = opt.is_set(ArgSettings::Multiple);
let mult = opt.is_set(ArgSettings::MultipleValues);
// @TODO @soundness: if doesn't have an equal, but requires equal is ValuesDone?!
if no_val && min_vals_zero && !has_eq && needs_eq {
debugln!("Parser::parse_opt: More arg vals not required...");
return Ok(ParseResult::ValuesDone);

View file

@ -96,7 +96,7 @@ impl<'a, 'b, 'c, 'z> Usage<'a, 'b, 'c, 'z> {
let has_last = positionals!(self.0.app).any(|p| p.is_set(ArgSettings::Last));
// places a '--' in the usage string if there are args and options
// supporting multiple values
if opts!(self.0.app).any(|o| o.is_set(ArgSettings::Multiple))
if opts!(self.0.app).any(|o| o.is_set(ArgSettings::MultipleValues))
&& positionals!(self.0.app).any(|p| !p.is_set(ArgSettings::Required))
&& !(self.0.app.has_visible_subcommands()
|| self.0.is_set(AS::AllowExternalSubcommands)) && !has_last

View file

@ -95,7 +95,7 @@ impl<'a, 'b, 'c, 'z> Validator<'a, 'b, 'c, 'z> {
if let Some(ref p_vals) = arg.possible_vals {
debugln!("Validator::validate_arg_values: possible_vals={:?}", p_vals);
let val_str = val.to_string_lossy();
let ok = if arg.is_set(ArgSettings::CaseInsensitive) {
let ok = if arg.is_set(ArgSettings::IgnoreCase) {
p_vals.iter().any(|pv| pv.eq_ignore_ascii_case(&*val_str))
} else {
p_vals.contains(&&*val_str)
@ -110,7 +110,7 @@ impl<'a, 'b, 'c, 'z> Validator<'a, 'b, 'c, 'z> {
));
}
}
if !arg.is_set(ArgSettings::EmptyValues) && val.is_empty_()
if !arg.is_set(ArgSettings::AllowEmptyValues) && val.is_empty_()
&& matcher.contains(&*arg.name)
{
debugln!("Validator::validate_arg_values: illegal empty val found");
@ -292,7 +292,7 @@ impl<'a, 'b, 'c, 'z> Validator<'a, 'b, 'c, 'z> {
matcher: &ArgMatcher<'a>,
) -> ClapResult<()> {
debugln!("Validator::validate_arg_num_occurs: a={};", a.name);
if ma.occurs > 1 && !a.is_set(ArgSettings::Multiple) {
if ma.occurs > 1 && !a.is_set(ArgSettings::MultipleOccurrences) {
// Not the first time, and we don't allow multiples
return Err(Error::unexpected_multiple_usage(
a,
@ -312,7 +312,7 @@ impl<'a, 'b, 'c, 'z> Validator<'a, 'b, 'c, 'z> {
debugln!("Validator::validate_arg_num_vals;");
if let Some(num) = a.num_vals {
debugln!("Validator::validate_arg_num_vals: num_vals set...{}", num);
let should_err = if a.is_set(ArgSettings::Multiple) {
let should_err = if a.is_set(ArgSettings::MultipleValues) {
((ma.vals.len() as u64) % num) != 0
} else {
num != (ma.vals.len() as u64)
@ -322,13 +322,14 @@ impl<'a, 'b, 'c, 'z> Validator<'a, 'b, 'c, 'z> {
return Err(Error::wrong_number_of_values(
a,
num,
if a.is_set(ArgSettings::Multiple) {
if a.is_set(ArgSettings::MultipleValues) {
(ma.vals.len() % num as usize)
} else {
ma.vals.len()
},
if ma.vals.len() == 1
|| (a.is_set(ArgSettings::Multiple) && (ma.vals.len() % num as usize) == 1)
|| (a.is_set(ArgSettings::MultipleValues)
&& (ma.vals.len() % num as usize) == 1)
{
"as"
} else {

File diff suppressed because it is too large Load diff

View file

@ -132,7 +132,7 @@ impl<'a> ArgMatcher<'a> {
if let Some(ma) = self.get(o.name) {
if let Some(num) = o.num_vals {
debugln!("ArgMatcher::needs_more_vals: num_vals...{}", num);
return if o.is_set(ArgSettings::Multiple) {
return if o.is_set(ArgSettings::MultipleValues) {
((ma.vals.len() as u64) % num) != 0
} else {
num != (ma.vals.len() as u64)
@ -144,7 +144,7 @@ impl<'a> ArgMatcher<'a> {
debugln!("ArgMatcher::needs_more_vals: min_vals...true");
return true;
}
return o.is_set(ArgSettings::Multiple);
return o.is_set(ArgSettings::MultipleValues);
}
true
}

View file

@ -336,11 +336,11 @@ impl<'a> ArgMatches<'a> {
/// # Examples
///
/// ```rust
/// # use clap::{App, Arg};
/// # use clap::{App, Arg, ArgSettings};
/// let m = App::new("myprog")
/// .arg(Arg::with_name("debug")
/// .short("d")
/// .multiple(true))
/// .setting(ArgSettings::MultipleOccurrences))
/// .get_matches_from(vec![
/// "myprog", "-d", "-d", "-d"
/// ]);
@ -351,11 +351,11 @@ impl<'a> ArgMatches<'a> {
/// This next example shows that counts actual uses of the argument, not just `-`'s
///
/// ```rust
/// # use clap::{App, Arg};
/// # use clap::{App, Arg, ArgSettings};
/// let m = App::new("myprog")
/// .arg(Arg::with_name("debug")
/// .short("d")
/// .multiple(true))
/// .setting(ArgSettings::MultipleOccurrences))
/// .arg(Arg::with_name("flag")
/// .short("f"))
/// .get_matches_from(vec![

File diff suppressed because it is too large Load diff

View file

@ -179,7 +179,9 @@ complete -F _{name} -o bashdefault -o default {name}
);
}
let num = vec.len();
if o.is_set(ArgSettings::Multiple) && num == 1 {
if (o.is_set(ArgSettings::MultipleValues) || o.is_set(ArgSettings::MultipleOccurrences))
&& num == 1
{
ret = format!("{}...", ret);
}
} else if let Some(num) = o.num_vals {
@ -192,12 +194,14 @@ complete -F _{name} -o bashdefault -o default {name}
if it.peek().is_some() { " " } else { "" }
);
}
if o.is_set(ArgSettings::Multiple) && num == 1 {
if (o.is_set(ArgSettings::MultipleValues) || o.is_set(ArgSettings::MultipleOccurrences))
&& num == 1
{
ret = format!("{}...", ret);
}
} else {
ret = format!("<{}>", o.name);
if o.is_set(ArgSettings::Multiple) {
if o.is_set(ArgSettings::MultipleValues) || o.is_set(ArgSettings::MultipleOccurrences) {
ret = format!("{}...", ret);
}
}

View file

@ -346,7 +346,11 @@ fn write_opts_of(p: &App) -> String {
format!("({})", conflicts)
};
let multiple = if o.is_set(ArgSettings::Multiple) {
// @TODO @soundness should probably be either multiple occurrences or multiple values and
// not both
let multiple = if o.is_set(ArgSettings::MultipleOccurrences)
|| o.is_set(ArgSettings::MultipleValues)
{
"*"
} else {
""
@ -407,7 +411,7 @@ fn write_flags_of(p: &App) -> String {
format!("({})", conflicts)
};
let multiple = if f.is_set(ArgSettings::Multiple) {
let multiple = if f.is_set(ArgSettings::MultipleOccurrences) {
"*"
} else {
""

View file

@ -108,12 +108,12 @@ pub enum ErrorKind {
/// # Examples
///
/// ```rust
/// # use clap::{App, Arg, ErrorKind};
/// # use clap::{App, Arg, ErrorKind, ArgSettings};
/// let res = App::new("prog")
/// .arg(Arg::with_name("color")
/// .long("color")
/// .empty_values(false))
/// .get_matches_from_safe(vec!["prog", "--color="]);
/// .setting(ArgSettings::TakesValue)
/// .long("color"))
/// .try_get_matches_from(vec!["prog", "--color="]);
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::EmptyValue);
/// ```
@ -136,7 +136,7 @@ pub enum ErrorKind {
/// let result = App::new("prog")
/// .arg(Arg::with_name("num")
/// .validator(is_numeric))
/// .get_matches_from_safe(vec!["prog", "NotANumber"]);
/// .try_get_matches_from(vec!["prog", "NotANumber"]);
/// assert!(result.is_err());
/// assert_eq!(result.unwrap_err().kind, ErrorKind::ValueValidation);
/// ```
@ -153,7 +153,7 @@ pub enum ErrorKind {
/// .arg(Arg::with_name("arg")
/// .multiple(true)
/// .max_values(2))
/// .get_matches_from_safe(vec!["prog", "too", "many", "values"]);
/// .try_get_matches_from(vec!["prog", "too", "many", "values"]);
/// assert!(result.is_err());
/// assert_eq!(result.unwrap_err().kind, ErrorKind::TooManyValues);
/// ```
@ -171,7 +171,7 @@ pub enum ErrorKind {
/// .arg(Arg::with_name("some_opt")
/// .long("opt")
/// .min_values(3))
/// .get_matches_from_safe(vec!["prog", "--opt", "too", "few"]);
/// .try_get_matches_from(vec!["prog", "--opt", "too", "few"]);
/// assert!(result.is_err());
/// assert_eq!(result.unwrap_err().kind, ErrorKind::TooFewValues);
/// ```
@ -191,7 +191,7 @@ pub enum ErrorKind {
/// .long("opt")
/// .takes_value(true)
/// .number_of_values(2))
/// .get_matches_from_safe(vec!["prog", "--opt", "wrong"]);
/// .try_get_matches_from(vec!["prog", "--opt", "wrong"]);
/// assert!(result.is_err());
/// assert_eq!(result.unwrap_err().kind, ErrorKind::WrongNumberOfValues);
/// ```
@ -213,7 +213,7 @@ pub enum ErrorKind {
/// .conflicts_with("color"))
/// .arg(Arg::with_name("color")
/// .long("color"))
/// .get_matches_from_safe(vec!["prog", "--debug", "--color"]);
/// .try_get_matches_from(vec!["prog", "--debug", "--color"]);
/// assert!(result.is_err());
/// assert_eq!(result.unwrap_err().kind, ErrorKind::ArgumentConflict);
/// ```

View file

@ -516,6 +516,8 @@
#![doc(html_root_url = "https://docs.rs/clap/2.29.2")]
#![deny(missing_docs, missing_debug_implementations, missing_copy_implementations, trivial_casts,
unused_import_braces, unused_allocation)]
// @TODO @v3-beta: remove me!
#![allow(deprecated)]
// Lints we'd like to deny but are currently failing for upstream crates
// unused_qualifications (bitflags, clippy)
// trivial_numeric_casts (bitflags)

File diff suppressed because it is too large Load diff