fix: Be consistent on hide/hidden

- `PossibleValue::hidden` -> `PossibleValue::hide` (new in clap3, no
  breakin change)

Fixes #33
This commit is contained in:
Ed Page 2021-11-29 10:45:30 -06:00
parent 57e5fc2b07
commit 62d7a3a928
7 changed files with 85 additions and 70 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

@ -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),
@ -3976,7 +3976,7 @@ impl<'help> Arg<'help> {
/// -V, --version Print version information
/// ```
#[inline]
pub fn hidden(self, h: bool) -> Self {
pub fn hide(self, h: bool) -> Self {
if h {
self.setting(ArgSettings::Hidden)
} else {
@ -3984,6 +3984,13 @@ impl<'help> Arg<'help> {
}
}
/// Deprecated, replaced with [`Arg::hide`]
#[deprecated(since = "3.0.0", note = "Replaced with `Arg::hide`")]
#[inline]
pub fn hidden(self, h: bool) -> Self {
self.hide(h)
}
/// Match values against [`Arg::possible_values`] without matching case.
///
/// When other arguments are conditionally required based on the
@ -4560,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"
@ -4597,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"
@ -4618,7 +4625,7 @@ impl<'help> Arg<'help> {
/// -V, --version Print version information
/// ```
#[inline]
pub fn hidden_short_help(self, hide: bool) -> Self {
pub fn hide_short_help(self, hide: bool) -> Self {
if hide {
self.setting(ArgSettings::HiddenShortHelp)
} else {
@ -4626,6 +4633,13 @@ impl<'help> Arg<'help> {
}
}
/// 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, h: bool) -> Self {
self.hide_short_help(h)
}
/// Hides an argument from long help (`--help`).
///
/// **NOTE:** This does **not** hide the argument from usage strings on error
@ -4635,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"
@ -4675,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"
@ -4696,7 +4704,7 @@ impl<'help> Arg<'help> {
/// -V, --version Print version information
/// ```
#[inline]
pub fn hidden_long_help(self, hide: bool) -> Self {
pub fn hide_long_help(self, hide: bool) -> Self {
if hide {
self.setting(ArgSettings::HiddenLongHelp)
} else {
@ -4704,6 +4712,13 @@ impl<'help> Arg<'help> {
}
}
/// 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, h: bool) -> Self {
self.hide_long_help(h)
}
/// 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

@ -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,7 +1162,7 @@ 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")
@ -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,