Merge pull request #38 from epage/rename

Handle more naming issues
This commit is contained in:
Ed Page 2021-11-29 12:10:22 -06:00 committed by GitHub
commit ac0f59ef73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 196 additions and 166 deletions

View file

@ -55,7 +55,7 @@ fn build_cli() -> App<'static> {
Arg::new("no-self-update")
.help("Don't perform self update when running the `rustup` command")
.long("no-self-update")
.hidden(true),
.hide(true),
),
)
.subcommand(

View file

@ -15,7 +15,7 @@ enum ArgChoice {
#[clap(alias = "b", alias = "z")]
Baz,
// Hiding variants from help and completion is supported
#[clap(hidden = true)]
#[clap(hide = true)]
Hidden,
}

View file

@ -837,8 +837,8 @@ impl Attrs {
self.is_enum
}
pub fn case_insensitive(&self) -> TokenStream {
let method = self.find_method("case_insensitive");
pub fn ignore_case(&self) -> TokenStream {
let method = self.find_method("ignore_case");
if let Some(method) = method {
method.args.clone()

View file

@ -558,7 +558,7 @@ fn gen_parsers(
FromFlag => (quote!(), quote!(), func.clone()),
};
if attrs.is_enum() {
let ci = attrs.case_insensitive();
let ci = attrs.ignore_case();
parse = quote_spanned! { convert_type.span()=>
|s| <#convert_type as clap::ArgEnum>::from_str(s, #ci).map_err(|err| clap::Error::raw(clap::ErrorKind::ValueValidation, format!("Invalid value for {}: {}", #name, err)))

View file

@ -79,7 +79,7 @@ pub fn arg_enum(name: &Ident) {
fn value_variants<'a>() -> &'a [Self]{
unimplemented!()
}
fn from_str(_input: &str, _case_insensitive: bool) -> Result<Self, String> {
fn from_str(_input: &str, _ignore_case: bool) -> Result<Self, String> {
unimplemented!()
}
fn to_possible_value<'a>(&self) -> Option<clap::PossibleValue<'a>>{

View file

@ -186,7 +186,7 @@ fn casing_propagation_is_overridden() {
}
#[test]
fn case_insensitive() {
fn ignore_case() {
#[derive(ArgEnum, PartialEq, Debug, Clone)]
enum ArgChoice {
Foo,
@ -194,7 +194,7 @@ fn case_insensitive() {
#[derive(Parser, PartialEq, Debug)]
struct Opt {
#[clap(arg_enum, case_insensitive(true))]
#[clap(arg_enum, ignore_case(true))]
arg: ArgChoice,
}
@ -213,7 +213,7 @@ fn case_insensitive() {
}
#[test]
fn case_insensitive_set_to_false() {
fn ignore_case_set_to_false() {
#[derive(ArgEnum, PartialEq, Debug, Clone)]
enum ArgChoice {
Foo,
@ -221,7 +221,7 @@ fn case_insensitive_set_to_false() {
#[derive(Parser, PartialEq, Debug)]
struct Opt {
#[clap(arg_enum, case_insensitive(false))]
#[clap(arg_enum, ignore_case(false))]
arg: ArgChoice,
}
@ -244,7 +244,7 @@ fn alias() {
#[derive(Parser, PartialEq, Debug)]
struct Opt {
#[clap(arg_enum, case_insensitive(false))]
#[clap(arg_enum, ignore_case(false))]
arg: ArgChoice,
}
@ -272,7 +272,7 @@ fn multiple_alias() {
#[derive(Parser, PartialEq, Debug)]
struct Opt {
#[clap(arg_enum, case_insensitive(false))]
#[clap(arg_enum, ignore_case(false))]
arg: ArgChoice,
}

View file

@ -10,7 +10,7 @@ use clap::Parser;
#[derive(Parser, Debug)]
struct Opt {
#[clap(raw(case_insensitive = "true"))]
#[clap(raw(ignore_case = "true"))]
s: String,
}

View file

@ -1,11 +1,11 @@
error: `#[clap(raw(...))` attributes are removed, they are replaced with raw methods
= help: if you meant to call `clap::Arg::raw()` method you should use bool literal, like `raw(true)` or `raw(false)`
= note: if you need to call `clap::Arg/App::case_insensitive` method you can do it like this: #[clap(case_insensitive = true)]
= note: if you need to call `clap::Arg/App::ignore_case` method you can do it like this: #[clap(ignore_case = true)]
--> $DIR/raw.rs:13:12
|
13 | #[clap(raw(case_insensitive = "true"))]
13 | #[clap(raw(ignore_case = "true"))]
| ^^^
error: `#[clap(raw(...))` attributes are removed, they are replaced with raw methods

View file

@ -113,6 +113,8 @@ impl_settings! { AppSettings, AppFlags,
=> Flags::PROPAGATE_VERSION,
GlobalVersion("propagateversion")
=> Flags::PROPAGATE_VERSION,
HidePossibleValues("hidepossiblevalues")
=> Flags::NO_POS_VALUES,
HidePossibleValuesInHelp("hidepossiblevaluesinhelp")
=> Flags::NO_POS_VALUES,
HelpExpected("helpexpected")
@ -786,6 +788,12 @@ pub enum AppSettings {
///
/// To set this per argument, see
/// [`Arg::hide_possible_values`][crate::Arg::hide_possible_values].
HidePossibleValues,
/// Deprecated, replaced with [`AppSettings::HidePossibleValues`]
#[deprecated(
since = "3.0.0",
note = "Replaced with AppSettings::HidePossibleValues"
)]
HidePossibleValuesInHelp,
/// Panic if help descriptions are omitted.
@ -1195,8 +1203,8 @@ mod test {
AppSettings::Hidden
);
assert_eq!(
"hidepossiblevaluesinhelp".parse::<AppSettings>().unwrap(),
AppSettings::HidePossibleValuesInHelp
"hidepossiblevalues".parse::<AppSettings>().unwrap(),
AppSettings::HidePossibleValues
);
assert_eq!(
"helpexpected".parse::<AppSettings>().unwrap(),

View file

@ -390,9 +390,9 @@ impl<'help> Arg<'help> {
"global" => yaml_to_bool!(a, v, global),
"multiple_occurrences" => yaml_to_bool!(a, v, multiple_occurrences),
"multiple_values" => yaml_to_bool!(a, v, multiple_values),
"hidden" => yaml_to_bool!(a, v, hidden),
"hidden_long_help" => yaml_to_bool!(a, v, hidden_long_help),
"hidden_short_help" => yaml_to_bool!(a, v, hidden_short_help),
"hide" => yaml_to_bool!(a, v, hide),
"hide_long_help" => yaml_to_bool!(a, v, hide_long_help),
"hide_short_help" => yaml_to_bool!(a, v, hide_short_help),
"next_line_help" => yaml_to_bool!(a, v, next_line_help),
"group" => yaml_to_str!(a, v, group),
"number_of_values" => yaml_to_usize!(a, v, number_of_values),
@ -434,7 +434,7 @@ impl<'help> Arg<'help> {
"overrides_with_all" => yaml_vec_or_str!(a, v, overrides_with),
"possible_value" => yaml_to_str!(a, v, possible_value),
"possible_values" => yaml_vec_or_str!(a, v, possible_value),
"case_insensitive" => yaml_to_bool!(a, v, case_insensitive),
"ignore_case" => yaml_to_bool!(a, v, ignore_case),
"required_unless_present_any" => yaml_vec!(a, v, required_unless_present_any),
"required_unless_present_all" => yaml_vec!(a, v, required_unless_present_all),
"visible_alias" => yaml_to_str!(a, v, visible_alias),
@ -1252,8 +1252,8 @@ impl<'help> Arg<'help> {
/// assert_eq!(res.unwrap_err().kind, ErrorKind::ArgumentConflict);
/// ```
#[inline]
pub fn exclusive(mut self, exclusive: bool) -> Self {
self.exclusive = exclusive;
pub fn exclusive(mut self, yes: bool) -> Self {
self.exclusive = yes;
self
}
@ -1642,7 +1642,7 @@ impl<'help> Arg<'help> {
/// .long("config"))
/// .arg(Arg::new("other")
/// .long("other")
/// .case_insensitive(true)
/// .ignore_case(true)
/// .takes_value(true))
/// .try_get_matches_from(vec![
/// "prog", "--other", "SPECIAL"
@ -2311,8 +2311,8 @@ impl<'help> Arg<'help> {
/// [`ArgMatches::value_of_lossy`]: crate::ArgMatches::value_of_lossy()
/// [`ArgMatches::values_of_lossy`]: crate::ArgMatches::values_of_lossy()
#[inline]
pub fn allow_invalid_utf8(self, tv: bool) -> Self {
if tv {
pub fn allow_invalid_utf8(self, yes: bool) -> Self {
if yes {
self.setting(ArgSettings::AllowInvalidUtf8)
} else {
self.unset_setting(ArgSettings::AllowInvalidUtf8)
@ -3537,8 +3537,8 @@ impl<'help> Arg<'help> {
/// [index]: Arg::index()
/// [`UnknownArgument`]: crate::ErrorKind::UnknownArgument
#[inline]
pub fn last(self, l: bool) -> Self {
if l {
pub fn last(self, yes: bool) -> Self {
if yes {
self.setting(ArgSettings::Last)
} else {
self.unset_setting(ArgSettings::Last)
@ -3599,8 +3599,8 @@ impl<'help> Arg<'help> {
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// ```
#[inline]
pub fn required(self, r: bool) -> Self {
if r {
pub fn required(self, yes: bool) -> Self {
if yes {
self.setting(ArgSettings::Required)
} else {
self.unset_setting(ArgSettings::Required)
@ -3639,8 +3639,8 @@ impl<'help> Arg<'help> {
/// [`Arg::value_delimiter(char)`]: Arg::value_delimiter()
/// [multiple values]: Arg::multiple_values
#[inline]
pub fn takes_value(self, tv: bool) -> Self {
if tv {
pub fn takes_value(self, yes: bool) -> Self {
if yes {
self.setting(ArgSettings::TakesValue)
} else {
self.unset_setting(ArgSettings::TakesValue)
@ -3698,8 +3698,8 @@ impl<'help> Arg<'help> {
/// ```
/// [`Arg::number_of_values(1)`]: Arg::number_of_values()
#[inline]
pub fn allow_hyphen_values(self, a: bool) -> Self {
if a {
pub fn allow_hyphen_values(self, yes: bool) -> Self {
if yes {
self.setting(ArgSettings::AllowHyphenValues)
} else {
self.unset_setting(ArgSettings::AllowHyphenValues)
@ -3749,8 +3749,8 @@ impl<'help> Arg<'help> {
/// assert_eq!(res.unwrap_err().kind, ErrorKind::NoEquals);
/// ```
#[inline]
pub fn require_equals(self, r: bool) -> Self {
if r {
pub fn require_equals(self, yes: bool) -> Self {
if yes {
self.setting(ArgSettings::RequireEquals)
} else {
self.unset_setting(ArgSettings::RequireEquals)
@ -3791,8 +3791,8 @@ impl<'help> Arg<'help> {
/// [`Subcommand`]: crate::Subcommand
/// [`ArgMatches::is_present("flag")`]: ArgMatches::is_present()
#[inline]
pub fn global(mut self, g: bool) -> Self {
self.global = g;
pub fn global(mut self, yes: bool) -> Self {
self.global = yes;
self
}
@ -3873,8 +3873,8 @@ impl<'help> Arg<'help> {
/// assert_eq!(delims.values_of("opt").unwrap().collect::<Vec<_>>(), ["val1", "val2", "val3"]);
/// ```
#[inline]
pub fn require_delimiter(self, d: bool) -> Self {
if d {
pub fn require_delimiter(self, yes: bool) -> Self {
if yes {
self.setting(ArgSettings::RequireDelimiter)
} else {
self.unset_setting(ArgSettings::RequireDelimiter)
@ -3889,7 +3889,7 @@ impl<'help> Arg<'help> {
/// **NOTE:** Setting this requires [`Arg::takes_value`]
///
/// To set this for all arguments, see
/// [`AppSettings::HidePossibleValuesInHelp`][crate::AppSettings::HidePossibleValuesInHelp].
/// [`AppSettings::HidePossibleValues`][crate::AppSettings::HidePossibleValues].
///
/// # Examples
///
@ -3905,8 +3905,8 @@ impl<'help> Arg<'help> {
/// If we were to run the above program with `--help` the `[values: fast, slow]` portion of
/// the help text would be omitted.
#[inline]
pub fn hide_possible_values(self, hide: bool) -> Self {
if hide {
pub fn hide_possible_values(self, yes: bool) -> Self {
if yes {
self.setting(ArgSettings::HidePossibleValues)
} else {
self.unset_setting(ArgSettings::HidePossibleValues)
@ -3935,8 +3935,8 @@ impl<'help> Arg<'help> {
/// If we were to run the above program with `--help` the `[default: localhost]` portion of
/// the help text would be omitted.
#[inline]
pub fn hide_default_value(self, hide: bool) -> Self {
if hide {
pub fn hide_default_value(self, yes: bool) -> Self {
if yes {
self.setting(ArgSettings::HideDefaultValue)
} else {
self.unset_setting(ArgSettings::HideDefaultValue)
@ -3976,14 +3976,21 @@ impl<'help> Arg<'help> {
/// -V, --version Print version information
/// ```
#[inline]
pub fn hidden(self, h: bool) -> Self {
if h {
pub fn hide(self, yes: bool) -> Self {
if yes {
self.setting(ArgSettings::Hidden)
} else {
self.unset_setting(ArgSettings::Hidden)
}
}
/// Deprecated, replaced with [`Arg::hide`]
#[deprecated(since = "3.0.0", note = "Replaced with `Arg::hide`")]
#[inline]
pub fn hidden(self, yes: bool) -> Self {
self.hide(yes)
}
/// Match values against [`Arg::possible_values`] without matching case.
///
/// When other arguments are conditionally required based on the
@ -4004,7 +4011,7 @@ impl<'help> Arg<'help> {
/// .arg(Arg::new("option")
/// .long("--option")
/// .takes_value(true)
/// .case_insensitive(true)
/// .ignore_case(true)
/// .possible_value("test123"))
/// .get_matches_from(vec![
/// "pv", "--option", "TeSt123",
@ -4022,7 +4029,7 @@ impl<'help> Arg<'help> {
/// .short('o')
/// .long("--option")
/// .takes_value(true)
/// .case_insensitive(true)
/// .ignore_case(true)
/// .multiple_values(true)
/// .possible_values(&["test123", "test321"]))
/// .get_matches_from(vec![
@ -4033,14 +4040,21 @@ impl<'help> Arg<'help> {
/// assert_eq!(&*matched_vals, &["TeSt123", "teST123", "tESt321"]);
/// ```
#[inline]
pub fn case_insensitive(self, ci: bool) -> Self {
if ci {
pub fn ignore_case(self, yes: bool) -> Self {
if yes {
self.setting(ArgSettings::IgnoreCase)
} else {
self.unset_setting(ArgSettings::IgnoreCase)
}
}
/// Deprecated, replaced with [`Arg::ignore_case`]
#[deprecated(since = "3.0.0", note = "Replaced with `Arg::ignore_case`")]
#[inline]
pub fn case_insensitive(self, yes: bool) -> Self {
self.ignore_case(yes)
}
/// Specifies that an argument should allow grouping of multiple values via a
/// delimiter.
///
@ -4091,8 +4105,8 @@ impl<'help> Arg<'help> {
/// ```
/// [`Arg::value_delimiter`]: Arg::value_delimiter()
#[inline]
pub fn use_delimiter(mut self, d: bool) -> Self {
if d {
pub fn use_delimiter(mut self, yes: bool) -> Self {
if yes {
if self.val_delim.is_none() {
self.val_delim = Some(',');
}
@ -4124,8 +4138,8 @@ impl<'help> Arg<'help> {
/// text would be omitted.
#[cfg(feature = "env")]
#[inline]
pub fn hide_env(self, hide: bool) -> Self {
if hide {
pub fn hide_env(self, yes: bool) -> Self {
if yes {
self.setting(ArgSettings::HideEnv)
} else {
self.unset_setting(ArgSettings::HideEnv)
@ -4153,8 +4167,8 @@ impl<'help> Arg<'help> {
/// `[default: CONNECT=super_secret]` portion of the help text would be omitted.
#[cfg(feature = "env")]
#[inline]
pub fn hide_env_values(self, hide: bool) -> Self {
if hide {
pub fn hide_env_values(self, yes: bool) -> Self {
if yes {
self.setting(ArgSettings::HideEnvValues)
} else {
self.unset_setting(ArgSettings::HideEnvValues)
@ -4205,8 +4219,8 @@ impl<'help> Arg<'help> {
/// on a line after the option
/// ```
#[inline]
pub fn next_line_help(self, nlh: bool) -> Self {
if nlh {
pub fn next_line_help(self, yes: bool) -> Self {
if yes {
self.setting(ArgSettings::NextLineHelp)
} else {
self.unset_setting(ArgSettings::NextLineHelp)
@ -4259,8 +4273,8 @@ impl<'help> Arg<'help> {
/// assert_eq!(res.unwrap_err().kind, ErrorKind::EmptyValue);
/// ```
#[inline]
pub fn forbid_empty_values(self, empty: bool) -> Self {
if empty {
pub fn forbid_empty_values(self, yes: bool) -> Self {
if yes {
self.setting(ArgSettings::ForbidEmptyValues)
} else {
self.unset_setting(ArgSettings::ForbidEmptyValues)
@ -4269,8 +4283,8 @@ impl<'help> Arg<'help> {
/// Deprecated, replaced with [`Arg::forbid_empty_values`]
#[deprecated(since = "3.0.0", note = "Replaced with `Arg::forbid_empty_values`")]
pub fn empty_values(self, empty: bool) -> Self {
self.forbid_empty_values(!empty)
pub fn empty_values(self, yes: bool) -> Self {
self.forbid_empty_values(!yes)
}
/// Specifies that the argument may have an unknown number of values
@ -4439,8 +4453,8 @@ impl<'help> Arg<'help> {
/// [maximum]: Arg::max_values()
/// [specific]: Arg::number_of_values()
#[inline]
pub fn multiple_values(self, multi: bool) -> Self {
if multi {
pub fn multiple_values(self, yes: bool) -> Self {
if yes {
self.setting(ArgSettings::MultipleValues)
} else {
self.unset_setting(ArgSettings::MultipleValues)
@ -4493,8 +4507,8 @@ impl<'help> Arg<'help> {
/// assert_eq!(files, ["file1", "file2", "file3"]);
/// ```
#[inline]
pub fn multiple_occurrences(self, multi: bool) -> Self {
if multi {
pub fn multiple_occurrences(self, yes: bool) -> Self {
if yes {
self.setting(ArgSettings::MultipleOccurrences)
} else {
self.unset_setting(ArgSettings::MultipleOccurrences)
@ -4507,8 +4521,8 @@ impl<'help> Arg<'help> {
since = "3.0.0",
note = "Split into `Arg::multiple_occurrences` (most likely what you want) and `Arg::multiple_values`"
)]
pub fn multiple(self, multi: bool) -> Self {
self.multiple_occurrences(multi).multiple_values(multi)
pub fn multiple(self, yes: bool) -> Self {
self.multiple_occurrences(yes).multiple_values(yes)
}
/// Consume all following arguments.
@ -4534,11 +4548,11 @@ impl<'help> Arg<'help> {
/// [`Arg::allow_hyphen_values(true)`]: Arg::allow_hyphen_values()
/// [`Arg::last(true)`]: Arg::last()
#[inline]
pub fn raw(self, raw: bool) -> Self {
self.takes_value(raw)
.multiple_values(raw)
.allow_hyphen_values(raw)
.last(raw)
pub fn raw(self, yes: bool) -> Self {
self.takes_value(yes)
.multiple_values(yes)
.allow_hyphen_values(yes)
.last(yes)
}
/// Hides an argument from short help (`-h`).
@ -4553,17 +4567,17 @@ impl<'help> Arg<'help> {
/// ```rust
/// # use clap::{App, Arg};
/// Arg::new("debug")
/// .hidden_short_help(true);
/// .hide_short_help(true);
/// ```
///
/// Setting `hidden_short_help(true)` will hide the argument when displaying short help text
/// Setting `hide_short_help(true)` will hide the argument when displaying short help text
///
/// ```rust
/// # use clap::{App, Arg};
/// let m = App::new("prog")
/// .arg(Arg::new("cfg")
/// .long("config")
/// .hidden_short_help(true)
/// .hide_short_help(true)
/// .help("Some help text describing the --config arg"))
/// .get_matches_from(vec![
/// "prog", "-h"
@ -4590,7 +4604,7 @@ impl<'help> Arg<'help> {
/// let m = App::new("prog")
/// .arg(Arg::new("cfg")
/// .long("config")
/// .hidden_short_help(true)
/// .hide_short_help(true)
/// .help("Some help text describing the --config arg"))
/// .get_matches_from(vec![
/// "prog", "--help"
@ -4611,14 +4625,21 @@ impl<'help> Arg<'help> {
/// -V, --version Print version information
/// ```
#[inline]
pub fn hidden_short_help(self, hide: bool) -> Self {
if hide {
pub fn hide_short_help(self, yes: bool) -> Self {
if yes {
self.setting(ArgSettings::HiddenShortHelp)
} else {
self.unset_setting(ArgSettings::HiddenShortHelp)
}
}
/// Deprecated, replaced with [`Arg::hide_short_help`]
#[deprecated(since = "3.0.0", note = "Replaced with `Arg::hide_short_help`")]
#[inline]
pub fn hidden_short_help(self, yes: bool) -> Self {
self.hide_short_help(yes)
}
/// Hides an argument from long help (`--help`).
///
/// **NOTE:** This does **not** hide the argument from usage strings on error
@ -4628,20 +4649,14 @@ impl<'help> Arg<'help> {
///
/// # Examples
///
/// ```rust
/// # use clap::{App, Arg};
/// Arg::new("debug")
/// .hidden_long_help(true)
/// # ;
/// ```
/// Setting `hidden_long_help(true)` will hide the argument when displaying long help text
/// Setting `hide_long_help(true)` will hide the argument when displaying long help text
///
/// ```rust
/// # use clap::{App, Arg};
/// let m = App::new("prog")
/// .arg(Arg::new("cfg")
/// .long("config")
/// .hidden_long_help(true)
/// .hide_long_help(true)
/// .help("Some help text describing the --config arg"))
/// .get_matches_from(vec![
/// "prog", "--help"
@ -4668,7 +4683,7 @@ impl<'help> Arg<'help> {
/// let m = App::new("prog")
/// .arg(Arg::new("cfg")
/// .long("config")
/// .hidden_long_help(true)
/// .hide_long_help(true)
/// .help("Some help text describing the --config arg"))
/// .get_matches_from(vec![
/// "prog", "-h"
@ -4689,14 +4704,21 @@ impl<'help> Arg<'help> {
/// -V, --version Print version information
/// ```
#[inline]
pub fn hidden_long_help(self, hide: bool) -> Self {
if hide {
pub fn hide_long_help(self, yes: bool) -> Self {
if yes {
self.setting(ArgSettings::HiddenLongHelp)
} else {
self.unset_setting(ArgSettings::HiddenLongHelp)
}
}
/// Deprecated, replaced with [`Arg::hide_long_help`]
#[deprecated(since = "3.0.0", note = "Replaced with `Arg::hide_long_help`")]
#[inline]
pub fn hidden_long_help(self, yes: bool) -> Self {
self.hide_long_help(yes)
}
/// Check if the [`ArgSettings`] variant is currently set on the argument.
///
/// [`ArgSettings`]: crate::ArgSettings

View file

@ -18,18 +18,18 @@ use crate::util::eq_ignore_case;
/// .value_name("FILE")
/// .possible_value(PossibleValue::new("fast"))
/// .possible_value(PossibleValue::new("slow").help("slower than fast"))
/// .possible_value(PossibleValue::new("secret speed").hidden(true));
/// .possible_value(PossibleValue::new("secret speed").hide(true));
/// ```
/// [Args]: crate::Arg
/// [possible values]: crate::Arg::possible_value()
/// [hide]: PossibleValue::hidden()
/// [hide]: PossibleValue::hide()
/// [help]: PossibleValue::help()
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct PossibleValue<'help> {
pub(crate) name: &'help str,
pub(crate) help: Option<&'help str>,
pub(crate) aliases: Vec<&'help str>, // (name, visible)
pub(crate) hidden: bool,
pub(crate) hide: bool,
}
impl<'help> From<&'help str> for PossibleValue<'help> {
@ -61,12 +61,12 @@ impl<'help> PossibleValue<'help> {
/// Should the value be hidden from help messages and completion
#[inline]
pub fn is_hidden(&self) -> bool {
self.hidden
self.hide
}
/// Get the name if argument value is not hidden, `None` otherwise
pub fn get_visible_name(&self) -> Option<&str> {
if self.hidden {
if self.hide {
None
} else {
Some(self.name)
@ -121,7 +121,7 @@ impl<'help> PossibleValue<'help> {
/// PossibleValue::new("fast")
/// # ;
/// ```
/// [hidden]: PossibleValue::hidden
/// [hidden]: PossibleValue::hide
/// [possible value]: crate::Arg::possible_values
/// [`Arg::hide_possible_values(true)`]: crate::Arg::hide_possible_values()
pub fn new(name: &'help str) -> Self {
@ -160,13 +160,13 @@ impl<'help> PossibleValue<'help> {
/// ```rust
/// # use clap::PossibleValue;
/// PossibleValue::new("secret")
/// .hidden(true)
/// .hide(true)
/// # ;
/// ```
/// [`Arg::hide_possible_values(true)`]: crate::Arg::hide_possible_values()
#[inline]
pub fn hidden(mut self, yes: bool) -> Self {
self.hidden = yes;
pub fn hide(mut self, yes: bool) -> Self {
self.hide = yes;
self
}

View file

@ -238,8 +238,8 @@ impl<'help> ArgGroup<'help> {
///
/// [`Arg`]: crate::Arg
#[inline]
pub fn multiple(mut self, m: bool) -> Self {
self.multiple = m;
pub fn multiple(mut self, yes: bool) -> Self {
self.multiple = yes;
self
}
@ -279,8 +279,8 @@ impl<'help> ArgGroup<'help> {
/// [`ArgGroup::multiple`]: ArgGroup::multiple()
/// [`App`]: crate::App
#[inline]
pub fn required(mut self, r: bool) -> Self {
self.required = r;
pub fn required(mut self, yes: bool) -> Self {
self.required = yes;
self
}

View file

@ -313,13 +313,13 @@ pub trait ArgEnum: Sized + Clone {
fn value_variants<'a>() -> &'a [Self];
/// Parse an argument into `Self`.
fn from_str(input: &str, case_insensitive: bool) -> Result<Self, String> {
fn from_str(input: &str, ignore_case: bool) -> Result<Self, String> {
Self::value_variants()
.iter()
.find(|v| {
v.to_possible_value()
.expect("ArgEnum::value_variants contains only values with a corresponding ArgEnum::to_possible_value")
.matches(input, case_insensitive)
.matches(input, ignore_case)
})
.cloned()
.ok_or_else(|| format!("Invalid variant: {}", input))

View file

@ -82,7 +82,7 @@ impl<'help, 'app, 'parser, 'writer> Help<'help, 'app, 'parser, 'writer> {
),
};
let next_line_help = parser.is_set(AppSettings::NextLineHelp);
let hide_pv = parser.is_set(AppSettings::HidePossibleValuesInHelp);
let hide_pv = parser.is_set(AppSettings::HidePossibleValues);
Help {
writer,

View file

@ -428,7 +428,7 @@ fn skip_possible_values() {
.author("Kevin K.")
.about("tests stuff")
.version("1.3")
.setting(AppSettings::HidePossibleValuesInHelp)
.setting(AppSettings::HidePossibleValues)
.args(&[
arg!(-o --opt <opt> "some option")
.required(false)

View file

@ -115,11 +115,11 @@ args:
long: exclusive
help: Tests 3 exclusive
exclusive: true
- case_insensitive:
- ignore_case:
index: 4
help: Test case_insensitive
help: Test ignore case
possible_values: [test123, test321]
case_insensitive: true
ignore_case: true
- value_hint:
long: value-hint
help: Test value_hint

View file

@ -1058,7 +1058,7 @@ fn hide_single_possible_val() {
.long("pos")
.value_name("VAL")
.possible_values(["fast", "slow"])
.possible_value(PossibleValue::new("secret speed").hidden(true))
.possible_value(PossibleValue::new("secret speed").hide(true))
.help("Some vals")
.takes_value(true),
)
@ -1162,13 +1162,13 @@ fn old_newline_chars() {
}
#[test]
fn issue_688_hidden_pos_vals() {
fn issue_688_hide_pos_vals() {
let filter_values = ["Nearest", "Linear", "Cubic", "Gaussian", "Lanczos3"];
let app1 = App::new("ctest")
.version("0.1")
.term_width(120)
.setting(AppSettings::HidePossibleValuesInHelp)
.setting(AppSettings::HidePossibleValues)
.arg(Arg::new("filter")
.help("Sets the filter, or sampling method, to use for interpolation when resizing the particle \
images. The default is Linear (Bilinear). [possible values: Nearest, Linear, Cubic, Gaussian, Lanczos3]")
@ -1382,12 +1382,12 @@ fn sc_negates_reqs() {
}
#[test]
fn hidden_args() {
fn hide_args() {
let app = App::new("prog")
.version("1.0")
.arg(arg!(-f --flag "testing flags"))
.arg(arg!(-o --opt <FILE> "tests options").required(false))
.arg(Arg::new("pos").hidden(true));
.arg(Arg::new("pos").hide(true));
assert!(utils::compare_output(
app,
"prog --help",
@ -1414,7 +1414,7 @@ fn args_negate_sc() {
}
#[test]
fn issue_1046_hidden_scs() {
fn issue_1046_hide_scs() {
let app = App::new("prog")
.version("1.0")
.arg(arg!(-f --flag "testing flags"))
@ -1637,7 +1637,7 @@ fn last_arg_mult_usage_with_sc() {
}
#[test]
fn hidden_default_val() {
fn hide_default_val() {
let app1 = App::new("default").version("0.1").term_width(120).arg(
Arg::new("argument")
.help("Pass an argument to the program. [default: default-argument]")
@ -1897,7 +1897,7 @@ SPECIAL:
";
#[test]
fn custom_help_headers_hidden_args() {
fn custom_help_headers_hide_args() {
let app = App::new("blorp")
.author("Will M.")
.about("does stuff")
@ -1908,7 +1908,7 @@ fn custom_help_headers_hidden_args() {
.short('n')
.long("no-proxy")
.help("Do not use system proxy settings")
.hidden_short_help(true),
.hide_short_help(true),
)
.help_heading(Some("SPECIAL"))
.arg(
@ -1925,7 +1925,7 @@ fn custom_help_headers_hidden_args() {
.long("server-addr")
.help("Set server address")
.help_heading(Some("NETWORKING"))
.hidden_short_help(true),
.hide_short_help(true),
);
assert!(utils::compare_output(
@ -2003,7 +2003,7 @@ fn issue_1364_no_short_options() {
Arg::new("baz")
.short('z')
.value_name("BAZ")
.hidden_short_help(true),
.hide_short_help(true),
)
.arg(
Arg::new("files")
@ -2403,7 +2403,7 @@ fn only_custom_heading_opts_no_args() {
let app = App::new("test")
.version("1.4")
.setting(AppSettings::DisableVersionFlag)
.mut_arg("help", |a| a.hidden(true))
.mut_arg("help", |a| a.hide(true))
.help_heading(Some("NETWORKING"))
.arg(arg!(-s --speed <SPEED> "How fast").required(false));
@ -2429,7 +2429,7 @@ fn only_custom_heading_pos_no_args() {
let app = App::new("test")
.version("1.4")
.setting(AppSettings::DisableVersionFlag)
.mut_arg("help", |a| a.hidden(true))
.mut_arg("help", |a| a.hide(true))
.help_heading(Some("NETWORKING"))
.arg(Arg::new("speed").help("How fast"));

View file

@ -19,16 +19,16 @@ OPTIONS:
";
#[test]
fn hidden_args() {
fn hide_args() {
let app = App::new("test")
.author("Kevin K.")
.about("tests stuff")
.version("1.4")
.args(&[
arg!(-f --flag "some flag").hidden(true),
arg!(-f --flag "some flag").hide(true),
arg!(-F --flag2 "some other flag"),
arg!(--option <opt> "some option").required(false),
Arg::new("DUMMY").hidden(true),
Arg::new("DUMMY").hide(true),
]);
assert!(utils::compare_output(
app,
@ -76,9 +76,9 @@ OPTIONS:
Print version information
";
/// Ensure hidden with short option
/// Ensure hide with short option
#[test]
fn hidden_short_args() {
fn hide_short_args() {
let app = App::new("test")
.about("hides short args")
.author("Steve P.")
@ -87,7 +87,7 @@ fn hidden_short_args() {
Arg::new("cfg")
.short('c')
.long("config")
.hidden_short_help(true)
.hide_short_help(true)
.help("Some help text describing the --config arg"),
Arg::new("visible")
.short('v')
@ -105,7 +105,7 @@ fn hidden_short_args() {
/// Ensure visible with opposite option
#[test]
fn hidden_short_args_long_help() {
fn hide_short_args_long_help() {
let app = App::new("test")
.about("hides short args")
.author("Steve P.")
@ -114,7 +114,7 @@ fn hidden_short_args_long_help() {
Arg::new("cfg")
.short('c')
.long("config")
.hidden_short_help(true)
.hide_short_help(true)
.help("Some help text describing the --config arg"),
Arg::new("visible")
.short('v')
@ -151,7 +151,7 @@ OPTIONS:
";
#[test]
fn hidden_long_args() {
fn hide_long_args() {
let app = App::new("test")
.about("hides long args")
.author("Steve P.")
@ -160,7 +160,7 @@ fn hidden_long_args() {
Arg::new("cfg")
.short('c')
.long("config")
.hidden_long_help(true)
.hide_long_help(true)
.help("Some help text describing the --config arg"),
Arg::new("visible")
.short('v')
@ -193,7 +193,7 @@ OPTIONS:
";
#[test]
fn hidden_long_args_short_help() {
fn hide_long_args_short_help() {
let app = App::new("test")
.about("hides long args")
.author("Steve P.")
@ -202,7 +202,7 @@ fn hidden_long_args_short_help() {
Arg::new("cfg")
.short('c')
.long("config")
.hidden_long_help(true)
.hide_long_help(true)
.help("Some help text describing the --config arg"),
Arg::new("visible")
.short('v')
@ -232,9 +232,9 @@ OPTIONS:
";
#[test]
fn hidden_pos_args() {
fn hide_pos_args() {
let app = App::new("test").version("1.4").args(&[
Arg::new("pos").help("some pos").hidden(true),
Arg::new("pos").help("some pos").hide(true),
Arg::new("another").help("another pos"),
]);
@ -257,7 +257,7 @@ OPTIONS:
";
#[test]
fn hidden_subcmds() {
fn hide_subcmds() {
let app = App::new("test")
.version("1.4")
.subcommand(App::new("sub").setting(AppSettings::Hidden));
@ -279,16 +279,16 @@ After help
";
#[test]
fn hidden_opt_args_only() {
fn hide_opt_args_only() {
let app = App::new("test")
.version("1.4")
.after_help("After help")
.mut_arg("help", |a| a.hidden(true))
.mut_arg("version", |a| a.hidden(true))
.mut_arg("help", |a| a.hide(true))
.mut_arg("version", |a| a.hide(true))
.arg(
arg!(--option <opt> "some option")
.required(false)
.hidden(true),
.hide(true),
);
assert!(utils::compare_output(
@ -308,13 +308,13 @@ After help
";
#[test]
fn hidden_pos_args_only() {
fn hide_pos_args_only() {
let app = App::new("test")
.version("1.4")
.after_help("After help")
.mut_arg("help", |a| a.hidden(true))
.mut_arg("version", |a| a.hidden(true))
.args(&[Arg::new("pos").help("some pos").hidden(true)]);
.mut_arg("help", |a| a.hide(true))
.mut_arg("version", |a| a.hide(true))
.args(&[Arg::new("pos").help("some pos").hide(true)]);
assert!(utils::compare_output(
app,
@ -333,12 +333,12 @@ After help
";
#[test]
fn hidden_subcmds_only() {
fn hide_subcmds_only() {
let app = App::new("test")
.version("1.4")
.after_help("After help")
.mut_arg("help", |a| a.hidden(true))
.mut_arg("version", |a| a.hidden(true))
.mut_arg("help", |a| a.hide(true))
.mut_arg("version", |a| a.hide(true))
.subcommand(App::new("sub").setting(AppSettings::Hidden));
assert!(utils::compare_output(

View file

@ -65,7 +65,7 @@ fn possible_value_arg_value() {
.arg(
Arg::new("arg_value").index(1).possible_value(
PossibleValue::new("test123")
.hidden(false)
.hide(false)
.help("It's just a test"),
),
)
@ -243,7 +243,7 @@ fn possible_values_hidden_output() {
.short('O')
.possible_values(["slow", "fast"])
.possible_value(PossibleValue::new("ludicrous speed"))
.possible_value(PossibleValue::new("forbidden speed").hidden(true))
.possible_value(PossibleValue::new("forbidden speed").hide(true))
),
"clap-test -O slo",
PV_ERROR,
@ -275,7 +275,7 @@ fn alias() {
.takes_value(true)
.possible_value(PossibleValue::new("test123").alias("123"))
.possible_value("test321")
.case_insensitive(true),
.ignore_case(true),
)
.try_get_matches_from(vec!["pv", "--option", "123"]);
@ -293,7 +293,7 @@ fn aliases() {
.takes_value(true)
.possible_value(PossibleValue::new("test123").aliases(["1", "2", "3"]))
.possible_value("test321")
.case_insensitive(true),
.ignore_case(true),
)
.try_get_matches_from(vec!["pv", "--option", "2"]);
@ -302,7 +302,7 @@ fn aliases() {
}
#[test]
fn case_insensitive() {
fn ignore_case() {
let m = App::new("pv")
.arg(
Arg::new("option")
@ -311,7 +311,7 @@ fn case_insensitive() {
.takes_value(true)
.possible_value("test123")
.possible_value("test321")
.case_insensitive(true),
.ignore_case(true),
)
.try_get_matches_from(vec!["pv", "--option", "TeSt123"]);
@ -324,7 +324,7 @@ fn case_insensitive() {
}
#[test]
fn case_insensitive_fail() {
fn ignore_case_fail() {
let m = App::new("pv")
.arg(
Arg::new("option")
@ -341,7 +341,7 @@ fn case_insensitive_fail() {
}
#[test]
fn case_insensitive_multiple() {
fn ignore_case_multiple() {
let m = App::new("pv")
.arg(
Arg::new("option")
@ -351,7 +351,7 @@ fn case_insensitive_multiple() {
.possible_value("test123")
.possible_value("test321")
.multiple_values(true)
.case_insensitive(true),
.ignore_case(true),
)
.try_get_matches_from(vec!["pv", "--option", "TeSt123", "teST123", "tESt321"]);
@ -363,7 +363,7 @@ fn case_insensitive_multiple() {
}
#[test]
fn case_insensitive_multiple_fail() {
fn ignore_case_multiple_fail() {
let m = App::new("pv")
.arg(
Arg::new("option")

View file

@ -543,7 +543,7 @@ fn required_if_val_present_fail() {
}
#[test]
fn required_if_val_present_case_insensitive_pass() {
fn required_if_val_present_ignore_case_pass() {
let res = App::new("ri")
.arg(
Arg::new("cfg")
@ -555,7 +555,7 @@ fn required_if_val_present_case_insensitive_pass() {
Arg::new("extra")
.takes_value(true)
.long("extra")
.case_insensitive(true),
.ignore_case(true),
)
.try_get_matches_from(vec!["ri", "--extra", "vaL", "--config", "my.cfg"]);
@ -563,7 +563,7 @@ fn required_if_val_present_case_insensitive_pass() {
}
#[test]
fn required_if_val_present_case_insensitive_fail() {
fn required_if_val_present_ignore_case_fail() {
let res = App::new("ri")
.arg(
Arg::new("cfg")
@ -575,7 +575,7 @@ fn required_if_val_present_case_insensitive_fail() {
Arg::new("extra")
.takes_value(true)
.long("extra")
.case_insensitive(true),
.ignore_case(true),
)
.try_get_matches_from(vec!["ri", "--extra", "vaL"]);

View file

@ -1,7 +1,7 @@
#![cfg(feature = "unicode")]
#[test]
fn possible_values_case_insensitive() {
fn possible_values_ignore_case() {
let m = clap::App::new("pv")
.arg(
clap::Arg::new("option")
@ -9,7 +9,7 @@ fn possible_values_case_insensitive() {
.long("--option")
.takes_value(true)
.possible_value("ä")
.case_insensitive(true),
.ignore_case(true),
)
.try_get_matches_from(vec!["pv", "--option", "Ä"]);