Remove v2 depecated features.

This patch:

* Removes the `ArgSettings::Global` variant, and replaces all
  users of it to `Arg::global(...)`. The variant itself is lifted up
  into a field on Arg. This was deprecated in clap 2.32.0.
* Removes AppFlags::PropagateGlobalValuesDown. This was deprecated in
  clap 2.27.0.
* Removes `Arg::empty_values`. This was deprecated in clap 2.30.0.
* Removes `ArgMatches::usage`. This was deprecated in clap 2.32.0.
This commit is contained in:
Erick Tryzelaar 2019-06-19 16:58:18 -07:00
parent 4a20c6aaef
commit cacc23473c
7 changed files with 16 additions and 90 deletions

View file

@ -19,7 +19,7 @@ macro_rules! create_app {
.author("Kevin K. <kbknapp@gmail.com>")
.arg("-o --option=[opt]... 'tests options'")
.arg("[positional] 'tests positionals'")
.arg(Arg::from("-f --flag... 'tests flags'").setting(ArgSettings::Global))
.arg(Arg::from("-f --flag... 'tests flags'").global(true))
.args(&[
Arg::from("[flag2] -F 'tests flags with exclusions'")
.conflicts_with("flag")
@ -76,7 +76,8 @@ fn create_app_builder(b: &mut Bencher) {
.short('f')
.help("tests flags")
.long("flag")
.settings(&[ArgSettings::MultipleOccurrences, ArgSettings::Global]),
.global(true)
.settings(&[ArgSettings::MultipleOccurrences]),
)
.arg(
Arg::with_name("flag2")

View file

@ -1398,7 +1398,7 @@ impl<'b> App<'b> {
.args
.args
.iter()
.filter(|a| a.is_set(ArgSettings::Global))
.filter(|a| a.global)
.map(|ga| ga.id)
.collect();
@ -1515,7 +1515,7 @@ impl<'b> App<'b> {
.args
.args
.iter()
.filter(|a| a.is_set(ArgSettings::Global))
.filter(|a| a.global)
{
$sc.args.push(a.clone());
}
@ -1666,7 +1666,7 @@ impl<'b> App<'b> {
);
}
assert!(
!(a.is_set(ArgSettings::Required) && a.is_set(ArgSettings::Global)),
!(a.is_set(ArgSettings::Required) && a.global),
"Global arguments cannot be required.\n\n\t'{}' is marked as \
global and required",
a.name

View file

@ -61,7 +61,6 @@ impl Default for AppFlags {
fn default() -> Self { AppFlags(Flags::UTF8_NONE | Flags::COLOR_AUTO) }
}
#[allow(deprecated)]
impl AppFlags {
pub fn new() -> Self { AppFlags::default() }
pub fn zeroed() -> Self { AppFlags(Flags::empty()) }
@ -90,7 +89,6 @@ impl AppFlags {
NoAutoHelp => Flags::NO_AUTO_HELP,
NoAutoVersion => Flags::NO_AUTO_VERSION,
NoBinaryName => Flags::NO_BIN_NAME,
PropagateGlobalValuesDown=> Flags::PROPAGATE_VALS_DOWN,
StrictUtf8 => Flags::UTF8_STRICT,
SubcommandsNegateReqs => Flags::SC_NEGATE_REQS,
SubcommandRequired => Flags::SC_REQUIRED,
@ -669,45 +667,6 @@ pub enum AppSettings {
/// ```
NextLineHelp,
/// **DEPRECATED**: This setting is no longer required in order to propagate values up or down
///
/// Specifies that the parser should propagate global arg's values down or up through any *used*
/// child subcommands. Meaning, if a subcommand wasn't used, the values won't be propagated to
/// said subcommand.
///
/// # Examples
///
/// ```rust
/// # use clap::{App, Arg, AppSettings, };
/// let m = App::new("myprog")
/// .arg(Arg::from("[cmd] 'command to run'")
/// .global(true))
/// .subcommand(App::new("foo"))
/// .get_matches_from(vec!["myprog", "set", "foo"]);
///
/// assert_eq!(m.value_of("cmd"), Some("set"));
///
/// let sub_m = m.subcommand_matches("foo").unwrap();
/// assert_eq!(sub_m.value_of("cmd"), Some("set"));
/// ```
/// Now doing the same thing, but *not* using any subcommands will result in the value not being
/// propagated down.
///
/// ```rust
/// # use clap::{App, Arg, AppSettings, };
/// let m = App::new("myprog")
/// .arg(Arg::from("[cmd] 'command to run'")
/// .global(true))
/// .subcommand(App::new("foo"))
/// .get_matches_from(vec!["myprog", "set"]);
///
/// assert_eq!(m.value_of("cmd"), Some("set"));
///
/// assert!(m.subcommand_matches("foo").is_none());
/// ```
#[deprecated(since = "2.27.0", note = "No longer required to propagate values")]
PropagateGlobalValuesDown,
/// Allows [``]s to override all requirements of the parent command.
/// For example if you had a subcommand or top level application with a required argument
/// that is only required as long as there is no subcommand present,

View file

@ -114,6 +114,8 @@ pub struct Arg<'help> {
pub r_ifs: Option<Vec<(Id, &'help str)>>,
#[doc(hidden)]
pub help_heading: Option<&'help str>,
#[doc(hidden)]
pub global: bool,
}
impl<'help> Arg<'help> {
@ -191,7 +193,6 @@ impl<'help> Arg<'help> {
"multiple" => yaml_to_bool!(a, v, multiple),
"hidden" => yaml_to_bool!(a, v, hidden),
"next_line_help" => yaml_to_bool!(a, v, next_line_help),
"empty_values" => yaml_to_bool!(a, v, empty_values),
"group" => yaml_to_str!(a, v, group),
"number_of_values" => yaml_to_u64!(a, v, number_of_values),
"max_values" => yaml_to_u64!(a, v, max_values),
@ -3020,7 +3021,7 @@ impl<'help> Arg<'help> {
/// # use clap::{App, Arg, ArgSettings};
/// Arg::with_name("debug")
/// .short('d')
/// .setting(ArgSettings::Global)
/// .global(true)
/// # ;
/// ```
///
@ -3034,7 +3035,7 @@ impl<'help> Arg<'help> {
/// .arg(Arg::with_name("verb")
/// .long("verbose")
/// .short('v')
/// .setting(ArgSettings::Global))
/// .global(true))
/// .subcommand(App::new("test"))
/// .subcommand(App::new("do-stuff"))
/// .get_matches_from(vec![
@ -3050,12 +3051,9 @@ impl<'help> Arg<'help> {
/// [`ArgMatches`]: ./struct.ArgMatches.html
/// [`ArgMatches::is_present("flag")`]: ./struct.ArgMatches.html#method.is_present
/// [`Arg`]: ./struct.Arg.html
pub fn global(self, g: bool) -> Self {
if g {
self.setting(ArgSettings::Global)
} else {
self.unset_setting(ArgSettings::Global)
}
pub fn global(mut self, g: bool) -> Self {
self.global = g;
self
}
/// Specifies that *multiple values* may only be set using the delimiter. This means if an
@ -3210,20 +3208,6 @@ impl<'help> Arg<'help> {
}
}
/// **Deprecated**
#[deprecated(
since = "2.30.0",
note = "Use `Arg::setting(ArgSettings::AllowEmptyValues)` instead. Will be removed in v3.0-beta"
)]
pub fn empty_values(mut self, ev: bool) -> Self {
if ev {
self.setting(ArgSettings::AllowEmptyValues)
} else {
self = self.setting(ArgSettings::TakesValue);
self.unset_setting(ArgSettings::AllowEmptyValues)
}
}
/// Hides an argument from help message output.
///
/// **NOTE:** This does **not** hide the argument from usage strings on error

View file

@ -40,7 +40,6 @@ impl ArgFlags {
MultipleOccurrences => Flags::MULTIPLE_OCC,
MultipleValues => Flags::MULTIPLE_VALS,
AllowEmptyValues => Flags::EMPTY_VALS,
Global => Flags::GLOBAL,
Hidden => Flags::HIDDEN,
TakesValue => Flags::TAKES_VAL,
UseValueDelimiter => Flags::USE_DELIM,
@ -82,10 +81,6 @@ pub enum ArgSettings {
MultipleOccurrences,
/// Allows an arg accept empty values such as `""`
AllowEmptyValues,
/// Sets an arg to be global (i.e. exist in all subcommands)
/// **DEPRECATED**
#[deprecated(since = "2.32.0", note = "Use `App::global_arg` instead")]
Global,
/// Hides an arg from the help message
Hidden,
/// Allows an argument to take a value (such as `--option value`)
@ -128,7 +123,6 @@ impl FromStr for ArgSettings {
fn from_str(s: &str) -> Result<Self, <Self as FromStr>::Err> {
match &*s.to_ascii_lowercase() {
"required" => Ok(ArgSettings::Required),
"global" => Ok(ArgSettings::Global),
"allowemptyvalues" => Ok(ArgSettings::AllowEmptyValues),
"hidden" => Ok(ArgSettings::Hidden),
"takesvalue" => Ok(ArgSettings::TakesValue),
@ -165,10 +159,6 @@ mod test {
"allowemptyvalues".parse::<ArgSettings>().unwrap(),
ArgSettings::AllowEmptyValues
);
assert_eq!(
"global".parse::<ArgSettings>().unwrap(),
ArgSettings::Global
);
assert_eq!(
"hidepossiblevalues".parse::<ArgSettings>().unwrap(),
ArgSettings::HidePossibleValues

View file

@ -744,14 +744,6 @@ impl ArgMatches {
.as_ref()
.map_or(("", None), |sc| (&sc.name[..], Some(&sc.matches)))
}
// @TODO @v3-beta: remove
/// **Deprecated**
#[deprecated(
since = "2.32.0",
note = "Use App::usage instead. Will be removed in v3-beta"
)]
pub fn usage(&self) -> &str { panic!("Use App::usage instead. Will be removed in v3-beta") }
}
// The following were taken and adapated from vec_map source

View file

@ -12,7 +12,7 @@ mod tests {
Arg::with_name("GLOBAL_ARG")
.long("global-arg")
.help("Specifies something needed by the subcommands")
.setting(ArgSettings::Global)
.global(true)
.setting(ArgSettings::TakesValue)
.default_value("default_value"),
)
@ -20,8 +20,8 @@ mod tests {
Arg::with_name("GLOBAL_FLAG")
.long("global-flag")
.help("Specifies something needed by the subcommands")
.setting(ArgSettings::MultipleOccurrences)
.setting(ArgSettings::Global),
.global(true)
.setting(ArgSettings::MultipleOccurrences),
)
.subcommand(App::new("outer").subcommand(App::new("inner")))
}