mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
Merge #1874
1874: Rename some internal stuff r=CreepySkeleton a=pksunkara Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
This commit is contained in:
commit
0bf70776de
4 changed files with 53 additions and 170 deletions
|
@ -77,8 +77,8 @@ pub struct App<'b> {
|
||||||
pub(crate) long_version: Option<&'b str>,
|
pub(crate) long_version: Option<&'b str>,
|
||||||
pub(crate) about: Option<&'b str>,
|
pub(crate) about: Option<&'b str>,
|
||||||
pub(crate) long_about: Option<&'b str>,
|
pub(crate) long_about: Option<&'b str>,
|
||||||
pub(crate) more_help: Option<&'b str>,
|
pub(crate) before_help: Option<&'b str>,
|
||||||
pub(crate) pre_help: Option<&'b str>,
|
pub(crate) after_help: Option<&'b str>,
|
||||||
pub(crate) aliases: Option<Vec<(&'b str, bool)>>, // (name, visible)
|
pub(crate) aliases: Option<Vec<(&'b str, bool)>>, // (name, visible)
|
||||||
pub(crate) usage_str: Option<&'b str>,
|
pub(crate) usage_str: Option<&'b str>,
|
||||||
pub(crate) usage: Option<String>,
|
pub(crate) usage: Option<String>,
|
||||||
|
@ -345,7 +345,7 @@ impl<'b> App<'b> {
|
||||||
/// # ;
|
/// # ;
|
||||||
/// ```
|
/// ```
|
||||||
pub fn after_help<S: Into<&'b str>>(mut self, help: S) -> Self {
|
pub fn after_help<S: Into<&'b str>>(mut self, help: S) -> Self {
|
||||||
self.more_help = Some(help.into());
|
self.after_help = Some(help.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,7 +362,7 @@ impl<'b> App<'b> {
|
||||||
/// # ;
|
/// # ;
|
||||||
/// ```
|
/// ```
|
||||||
pub fn before_help<S: Into<&'b str>>(mut self, help: S) -> Self {
|
pub fn before_help<S: Into<&'b str>>(mut self, help: S) -> Self {
|
||||||
self.pre_help = Some(help.into());
|
self.before_help = Some(help.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -235,7 +235,7 @@ impl<'help> Arg<'help> {
|
||||||
"required_unless_one" => yaml_vec_or_str!(v, a, required_unless),
|
"required_unless_one" => yaml_vec_or_str!(v, a, required_unless),
|
||||||
"required_unless_all" => {
|
"required_unless_all" => {
|
||||||
a = yaml_vec_or_str!(v, a, required_unless);
|
a = yaml_vec_or_str!(v, a, required_unless);
|
||||||
a.setb(ArgSettings::RequiredUnlessAll);
|
a.set_mut(ArgSettings::RequiredUnlessAll);
|
||||||
a
|
a
|
||||||
}
|
}
|
||||||
s => panic!(
|
s => panic!(
|
||||||
|
@ -452,128 +452,14 @@ impl<'help> Arg<'help> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the short help text of the argument that will be displayed to the user when they print
|
/// See [`Arg::about`](./struct.Arg.html#method.about)
|
||||||
/// the help information with `-h`. Typically, this is a short (one line) description of the
|
|
||||||
/// arg.
|
|
||||||
///
|
|
||||||
/// **NOTE:** If only `Arg::help` is provided, and not [`Arg::long_help`] but the user requests
|
|
||||||
/// `--help` clap will still display the contents of `help` appropriately
|
|
||||||
///
|
|
||||||
/// **NOTE:** Only `Arg::help` is used in completion script generation in order to be concise
|
|
||||||
///
|
|
||||||
/// # Examples
|
|
||||||
///
|
|
||||||
/// Any valid UTF-8 is allowed in the help text. The one exception is when one wishes to
|
|
||||||
/// include a newline in the help text and have the following text be properly aligned with all
|
|
||||||
/// the other help text.
|
|
||||||
///
|
|
||||||
/// ```rust
|
|
||||||
/// # use clap::{App, Arg};
|
|
||||||
/// Arg::with_name("config")
|
|
||||||
/// .help("The config file used by the myprog")
|
|
||||||
/// # ;
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// Setting `help` displays a short message to the side of the argument when the user passes
|
|
||||||
/// `-h` or `--help` (by default).
|
|
||||||
///
|
|
||||||
/// ```rust
|
|
||||||
/// # use clap::{App, Arg};
|
|
||||||
/// let m = App::new("prog")
|
|
||||||
/// .arg(Arg::with_name("cfg")
|
|
||||||
/// .long("config")
|
|
||||||
/// .help("Some help text describing the --config arg"))
|
|
||||||
/// .get_matches_from(vec![
|
|
||||||
/// "prog", "--help"
|
|
||||||
/// ]);
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// The above example displays
|
|
||||||
///
|
|
||||||
/// ```text
|
|
||||||
/// helptest
|
|
||||||
///
|
|
||||||
/// USAGE:
|
|
||||||
/// helptest [FLAGS]
|
|
||||||
///
|
|
||||||
/// FLAGS:
|
|
||||||
/// --config Some help text describing the --config arg
|
|
||||||
/// -h, --help Prints help information
|
|
||||||
/// -V, --version Prints version information
|
|
||||||
/// ```
|
|
||||||
/// [`Arg::long_help`]: ./struct.Arg.html#method.long_help
|
|
||||||
#[deprecated(since = "3.0.0", note = "Please use `about` method instead")]
|
#[deprecated(since = "3.0.0", note = "Please use `about` method instead")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn help(self, h: &'help str) -> Self {
|
pub fn help(self, h: &'help str) -> Self {
|
||||||
self.about(h)
|
self.about(h)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the long help text of the argument that will be displayed to the user when they print
|
/// See [`Arg::long_about`](./struct.Arg.html#method.long_about)
|
||||||
/// the help information with `--help`. Typically this a more detailed (multi-line) message
|
|
||||||
/// that describes the arg.
|
|
||||||
///
|
|
||||||
/// **NOTE:** If only `long_help` is provided, and not [`Arg::help`] but the user requests `-h`
|
|
||||||
/// clap will still display the contents of `long_help` appropriately
|
|
||||||
///
|
|
||||||
/// **NOTE:** Only [`Arg::help`] is used in completion script generation in order to be concise
|
|
||||||
///
|
|
||||||
/// # Examples
|
|
||||||
///
|
|
||||||
/// Any valid UTF-8 is allowed in the help text. The one exception is when one wishes to
|
|
||||||
/// include a newline in the help text and have the following text be properly aligned with all
|
|
||||||
/// the other help text.
|
|
||||||
///
|
|
||||||
/// ```rust
|
|
||||||
/// # use clap::{App, Arg};
|
|
||||||
/// Arg::with_name("config")
|
|
||||||
/// .long_help(
|
|
||||||
/// "The config file used by the myprog must be in JSON format
|
|
||||||
/// with only valid keys and may not contain other nonsense
|
|
||||||
/// that cannot be read by this program. Obviously I'm going on
|
|
||||||
/// and on, so I'll stop now.")
|
|
||||||
/// # ;
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// Setting `help` displays a short message to the side of the argument when the user passes
|
|
||||||
/// `-h` or `--help` (by default).
|
|
||||||
///
|
|
||||||
/// ```rust
|
|
||||||
/// # use clap::{App, Arg};
|
|
||||||
/// let m = App::new("prog")
|
|
||||||
/// .arg(Arg::with_name("cfg")
|
|
||||||
/// .long("config")
|
|
||||||
/// .long_help(
|
|
||||||
/// "The config file used by the myprog must be in JSON format
|
|
||||||
/// with only valid keys and may not contain other nonsense
|
|
||||||
/// that cannot be read by this program. Obviously I'm going on
|
|
||||||
/// and on, so I'll stop now."))
|
|
||||||
/// .get_matches_from(vec![
|
|
||||||
/// "prog", "--help"
|
|
||||||
/// ]);
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// The above example displays
|
|
||||||
///
|
|
||||||
/// ```notrust
|
|
||||||
/// helptest
|
|
||||||
///
|
|
||||||
/// USAGE:
|
|
||||||
/// helptest [FLAGS]
|
|
||||||
///
|
|
||||||
/// FLAGS:
|
|
||||||
/// --config
|
|
||||||
/// The config file used by the myprog must be in JSON format
|
|
||||||
/// with only valid keys and may not contain other nonsense
|
|
||||||
/// that cannot be read by this program. Obviously I'm going on
|
|
||||||
/// and on, so I'll stop now.
|
|
||||||
///
|
|
||||||
/// -h, --help
|
|
||||||
/// Prints help information
|
|
||||||
///
|
|
||||||
/// -V, --version
|
|
||||||
/// Prints version information
|
|
||||||
/// ```
|
|
||||||
/// [`Arg::help`]: ./struct.Arg.html#method.help
|
|
||||||
#[deprecated(since = "3.0.0", note = "Please use `long_about` method instead")]
|
#[deprecated(since = "3.0.0", note = "Please use `long_about` method instead")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn long_help(self, h: &'help str) -> Self {
|
pub fn long_help(self, h: &'help str) -> Self {
|
||||||
|
@ -1769,7 +1655,7 @@ impl<'help> Arg<'help> {
|
||||||
/// [`max_values`]: ./struct.Arg.html#method.max_values
|
/// [`max_values`]: ./struct.Arg.html#method.max_values
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn value_terminator(mut self, term: &'help str) -> Self {
|
pub fn value_terminator(mut self, term: &'help str) -> Self {
|
||||||
self.setb(ArgSettings::TakesValue);
|
self.set_mut(ArgSettings::TakesValue);
|
||||||
self.terminator = Some(term);
|
self.terminator = Some(term);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -1822,7 +1708,7 @@ impl<'help> Arg<'help> {
|
||||||
/// [options]: ./struct.Arg.html#method.takes_value
|
/// [options]: ./struct.Arg.html#method.takes_value
|
||||||
/// [positional arguments]: ./struct.Arg.html#method.index
|
/// [positional arguments]: ./struct.Arg.html#method.index
|
||||||
pub fn possible_values(mut self, names: &[&'help str]) -> Self {
|
pub fn possible_values(mut self, names: &[&'help str]) -> Self {
|
||||||
self.setb(ArgSettings::TakesValue);
|
self.set_mut(ArgSettings::TakesValue);
|
||||||
if let Some(ref mut vec) = self.possible_vals {
|
if let Some(ref mut vec) = self.possible_vals {
|
||||||
for s in names {
|
for s in names {
|
||||||
vec.push(s);
|
vec.push(s);
|
||||||
|
@ -1887,7 +1773,7 @@ impl<'help> Arg<'help> {
|
||||||
/// [options]: ./struct.Arg.html#method.takes_value
|
/// [options]: ./struct.Arg.html#method.takes_value
|
||||||
/// [positional arguments]: ./struct.Arg.html#method.index
|
/// [positional arguments]: ./struct.Arg.html#method.index
|
||||||
pub fn possible_value(mut self, name: &'help str) -> Self {
|
pub fn possible_value(mut self, name: &'help str) -> Self {
|
||||||
self.setb(ArgSettings::TakesValue);
|
self.set_mut(ArgSettings::TakesValue);
|
||||||
if let Some(ref mut vec) = self.possible_vals {
|
if let Some(ref mut vec) = self.possible_vals {
|
||||||
vec.push(name);
|
vec.push(name);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2016,7 +1902,7 @@ impl<'help> Arg<'help> {
|
||||||
/// [`Arg::multiple(true)`]: ./struct.Arg.html#method.multiple
|
/// [`Arg::multiple(true)`]: ./struct.Arg.html#method.multiple
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn number_of_values(mut self, qty: u64) -> Self {
|
pub fn number_of_values(mut self, qty: u64) -> Self {
|
||||||
self.setb(ArgSettings::TakesValue);
|
self.set_mut(ArgSettings::TakesValue);
|
||||||
self.num_vals = Some(qty);
|
self.num_vals = Some(qty);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -2163,10 +2049,9 @@ impl<'help> Arg<'help> {
|
||||||
/// ```
|
/// ```
|
||||||
/// [`Arg::multiple(true)`]: ./struct.Arg.html#method.multiple
|
/// [`Arg::multiple(true)`]: ./struct.Arg.html#method.multiple
|
||||||
#[inline]
|
#[inline]
|
||||||
#[inline]
|
|
||||||
pub fn max_values(mut self, qty: u64) -> Self {
|
pub fn max_values(mut self, qty: u64) -> Self {
|
||||||
self.setb(ArgSettings::TakesValue);
|
self.set_mut(ArgSettings::TakesValue);
|
||||||
self.setb(ArgSettings::MultipleValues);
|
self.set_mut(ArgSettings::MultipleValues);
|
||||||
self.max_vals = Some(qty);
|
self.max_vals = Some(qty);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -2259,9 +2144,9 @@ impl<'help> Arg<'help> {
|
||||||
/// [`Arg::takes_value(true)`]: ./struct.Arg.html#method.takes_value
|
/// [`Arg::takes_value(true)`]: ./struct.Arg.html#method.takes_value
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn value_delimiter(mut self, d: &str) -> Self {
|
pub fn value_delimiter(mut self, d: &str) -> Self {
|
||||||
self.unsetb(ArgSettings::ValueDelimiterNotSet);
|
self.unset_mut(ArgSettings::ValueDelimiterNotSet);
|
||||||
self.setb(ArgSettings::TakesValue);
|
self.set_mut(ArgSettings::TakesValue);
|
||||||
self.setb(ArgSettings::UseValueDelimiter);
|
self.set_mut(ArgSettings::UseValueDelimiter);
|
||||||
self.val_delim = Some(
|
self.val_delim = Some(
|
||||||
d.chars()
|
d.chars()
|
||||||
.next()
|
.next()
|
||||||
|
@ -2330,10 +2215,10 @@ impl<'help> Arg<'help> {
|
||||||
/// [`Arg::takes_value(true)`]: ./struct.Arg.html#method.takes_value
|
/// [`Arg::takes_value(true)`]: ./struct.Arg.html#method.takes_value
|
||||||
/// [`Arg::multiple(true)`]: ./struct.Arg.html#method.multiple
|
/// [`Arg::multiple(true)`]: ./struct.Arg.html#method.multiple
|
||||||
pub fn value_names(mut self, names: &[&'help str]) -> Self {
|
pub fn value_names(mut self, names: &[&'help str]) -> Self {
|
||||||
self.setb(ArgSettings::TakesValue);
|
self.set_mut(ArgSettings::TakesValue);
|
||||||
if self.is_set(ArgSettings::ValueDelimiterNotSet) {
|
if self.is_set(ArgSettings::ValueDelimiterNotSet) {
|
||||||
self.unsetb(ArgSettings::ValueDelimiterNotSet);
|
self.unset_mut(ArgSettings::ValueDelimiterNotSet);
|
||||||
self.setb(ArgSettings::UseValueDelimiter);
|
self.set_mut(ArgSettings::UseValueDelimiter);
|
||||||
}
|
}
|
||||||
if let Some(ref mut vals) = self.val_names {
|
if let Some(ref mut vals) = self.val_names {
|
||||||
let mut l = vals.len();
|
let mut l = vals.len();
|
||||||
|
@ -2398,7 +2283,7 @@ impl<'help> Arg<'help> {
|
||||||
/// [positional]: ./struct.Arg.html#method.index
|
/// [positional]: ./struct.Arg.html#method.index
|
||||||
/// [`Arg::takes_value(true)`]: ./struct.Arg.html#method.takes_value
|
/// [`Arg::takes_value(true)`]: ./struct.Arg.html#method.takes_value
|
||||||
pub fn value_name(mut self, name: &'help str) -> Self {
|
pub fn value_name(mut self, name: &'help str) -> Self {
|
||||||
self.setb(ArgSettings::TakesValue);
|
self.set_mut(ArgSettings::TakesValue);
|
||||||
if let Some(ref mut vals) = self.val_names {
|
if let Some(ref mut vals) = self.val_names {
|
||||||
let l = vals.len();
|
let l = vals.len();
|
||||||
vals.insert(l, name);
|
vals.insert(l, name);
|
||||||
|
@ -2501,7 +2386,7 @@ impl<'help> Arg<'help> {
|
||||||
/// [`OsStr`]: https://doc.rust-lang.org/std/ffi/struct.OsStr.html
|
/// [`OsStr`]: https://doc.rust-lang.org/std/ffi/struct.OsStr.html
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn default_values_os(mut self, vals: &[&'help OsStr]) -> Self {
|
pub fn default_values_os(mut self, vals: &[&'help OsStr]) -> Self {
|
||||||
self.setb(ArgSettings::TakesValue);
|
self.set_mut(ArgSettings::TakesValue);
|
||||||
self.default_vals = Some(vals.to_vec());
|
self.default_vals = Some(vals.to_vec());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -2622,7 +2507,7 @@ impl<'help> Arg<'help> {
|
||||||
default: &'help OsStr,
|
default: &'help OsStr,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let arg = arg_id.into();
|
let arg = arg_id.into();
|
||||||
self.setb(ArgSettings::TakesValue);
|
self.set_mut(ArgSettings::TakesValue);
|
||||||
if let Some(ref mut vm) = self.default_vals_ifs {
|
if let Some(ref mut vm) = self.default_vals_ifs {
|
||||||
let l = vm.len();
|
let l = vm.len();
|
||||||
vm.insert(l, (arg, val, default));
|
vm.insert(l, (arg, val, default));
|
||||||
|
@ -2852,7 +2737,7 @@ impl<'help> Arg<'help> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn env_os(mut self, name: &'help OsStr) -> Self {
|
pub fn env_os(mut self, name: &'help OsStr) -> Self {
|
||||||
if !self.is_set(ArgSettings::MultipleOccurrences) {
|
if !self.is_set(ArgSettings::MultipleOccurrences) {
|
||||||
self.setb(ArgSettings::TakesValue);
|
self.set_mut(ArgSettings::TakesValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.env = Some((name, env::var_os(name)));
|
self.env = Some((name, env::var_os(name)));
|
||||||
|
@ -3233,7 +3118,7 @@ impl<'help> Arg<'help> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn require_equals(mut self, r: bool) -> Self {
|
pub fn require_equals(mut self, r: bool) -> Self {
|
||||||
if r {
|
if r {
|
||||||
self.unsetb(ArgSettings::AllowEmptyValues);
|
self.unset_mut(ArgSettings::AllowEmptyValues);
|
||||||
self.setting(ArgSettings::RequireEquals)
|
self.setting(ArgSettings::RequireEquals)
|
||||||
} else {
|
} else {
|
||||||
self.unset_setting(ArgSettings::RequireEquals)
|
self.unset_setting(ArgSettings::RequireEquals)
|
||||||
|
@ -3361,13 +3246,13 @@ impl<'help> Arg<'help> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn require_delimiter(mut self, d: bool) -> Self {
|
pub fn require_delimiter(mut self, d: bool) -> Self {
|
||||||
if d {
|
if d {
|
||||||
self.setb(ArgSettings::UseValueDelimiter);
|
self.set_mut(ArgSettings::UseValueDelimiter);
|
||||||
self.unsetb(ArgSettings::ValueDelimiterNotSet);
|
self.unset_mut(ArgSettings::ValueDelimiterNotSet);
|
||||||
self.setb(ArgSettings::UseValueDelimiter);
|
self.set_mut(ArgSettings::UseValueDelimiter);
|
||||||
self.setting(ArgSettings::RequireDelimiter)
|
self.setting(ArgSettings::RequireDelimiter)
|
||||||
} else {
|
} else {
|
||||||
self.unsetb(ArgSettings::UseValueDelimiter);
|
self.unset_mut(ArgSettings::UseValueDelimiter);
|
||||||
self.unsetb(ArgSettings::UseValueDelimiter);
|
self.unset_mut(ArgSettings::UseValueDelimiter);
|
||||||
self.unset_setting(ArgSettings::RequireDelimiter)
|
self.unset_setting(ArgSettings::RequireDelimiter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3592,12 +3477,12 @@ impl<'help> Arg<'help> {
|
||||||
if self.val_delim.is_none() {
|
if self.val_delim.is_none() {
|
||||||
self.val_delim = Some(',');
|
self.val_delim = Some(',');
|
||||||
}
|
}
|
||||||
self.setb(ArgSettings::TakesValue);
|
self.set_mut(ArgSettings::TakesValue);
|
||||||
self.setb(ArgSettings::UseValueDelimiter);
|
self.set_mut(ArgSettings::UseValueDelimiter);
|
||||||
self.unset_setting(ArgSettings::ValueDelimiterNotSet)
|
self.unset_setting(ArgSettings::ValueDelimiterNotSet)
|
||||||
} else {
|
} else {
|
||||||
self.val_delim = None;
|
self.val_delim = None;
|
||||||
self.unsetb(ArgSettings::UseValueDelimiter);
|
self.unset_mut(ArgSettings::UseValueDelimiter);
|
||||||
self.unset_setting(ArgSettings::ValueDelimiterNotSet)
|
self.unset_setting(ArgSettings::ValueDelimiterNotSet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3686,9 +3571,9 @@ impl<'help> Arg<'help> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn next_line_help(mut self, nlh: bool) -> Self {
|
pub fn next_line_help(mut self, nlh: bool) -> Self {
|
||||||
if nlh {
|
if nlh {
|
||||||
self.setb(ArgSettings::NextLineHelp);
|
self.set_mut(ArgSettings::NextLineHelp);
|
||||||
} else {
|
} else {
|
||||||
self.unsetb(ArgSettings::NextLineHelp);
|
self.unset_mut(ArgSettings::NextLineHelp);
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -3875,10 +3760,10 @@ impl<'help> Arg<'help> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn multiple(mut self, multi: bool) -> Self {
|
pub fn multiple(mut self, multi: bool) -> Self {
|
||||||
if multi {
|
if multi {
|
||||||
self.setb(ArgSettings::MultipleOccurrences);
|
self.set_mut(ArgSettings::MultipleOccurrences);
|
||||||
self.setting(ArgSettings::MultipleValues)
|
self.setting(ArgSettings::MultipleValues)
|
||||||
} else {
|
} else {
|
||||||
self.unsetb(ArgSettings::MultipleOccurrences);
|
self.unset_mut(ArgSettings::MultipleOccurrences);
|
||||||
self.unset_setting(ArgSettings::MultipleValues)
|
self.unset_setting(ArgSettings::MultipleValues)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4203,7 +4088,7 @@ impl<'help> Arg<'help> {
|
||||||
/// [`ArgSettings`]: ./enum.ArgSettings.html
|
/// [`ArgSettings`]: ./enum.ArgSettings.html
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn setting(mut self, s: ArgSettings) -> Self {
|
pub fn setting(mut self, s: ArgSettings) -> Self {
|
||||||
self.setb(s);
|
self.set_mut(s);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4221,7 +4106,7 @@ impl<'help> Arg<'help> {
|
||||||
/// [`ArgSettings`]: ./enum.ArgSettings.html
|
/// [`ArgSettings`]: ./enum.ArgSettings.html
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn unset_setting(mut self, s: ArgSettings) -> Self {
|
pub fn unset_setting(mut self, s: ArgSettings) -> Self {
|
||||||
self.unsetb(s);
|
self.unset_mut(s);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4246,8 +4131,8 @@ impl<'help> Arg<'help> {
|
||||||
|| self.min_vals.is_some()
|
|| self.min_vals.is_some()
|
||||||
|| (self.num_vals.is_some() && self.num_vals.unwrap() > 1)
|
|| (self.num_vals.is_some() && self.num_vals.unwrap() > 1)
|
||||||
{
|
{
|
||||||
self.setb(ArgSettings::MultipleValues);
|
self.set_mut(ArgSettings::MultipleValues);
|
||||||
self.setb(ArgSettings::MultipleOccurrences);
|
self.set_mut(ArgSettings::MultipleOccurrences);
|
||||||
}
|
}
|
||||||
} else if self.is_set(ArgSettings::TakesValue) {
|
} else if self.is_set(ArgSettings::TakesValue) {
|
||||||
if let Some(ref vec) = self.val_names {
|
if let Some(ref vec) = self.val_names {
|
||||||
|
@ -4258,13 +4143,11 @@ impl<'help> Arg<'help> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @TODO @p6 @naming @internal: rename to set_mut
|
pub(crate) fn set_mut(&mut self, s: ArgSettings) {
|
||||||
pub(crate) fn setb(&mut self, s: ArgSettings) {
|
|
||||||
self.settings.set(s);
|
self.settings.set(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @TODO @p6 @naming @internal: rename to unset_mut
|
pub(crate) fn unset_mut(&mut self, s: ArgSettings) {
|
||||||
pub(crate) fn unsetb(&mut self, s: ArgSettings) {
|
|
||||||
self.settings.unset(s);
|
self.settings.unset(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4616,7 +4499,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn positiona_display_mult() {
|
fn positiona_display_mult() {
|
||||||
let mut p = Arg::with_name("pos").index(1);
|
let mut p = Arg::with_name("pos").index(1);
|
||||||
p.setb(ArgSettings::MultipleValues);
|
p.set_mut(ArgSettings::MultipleValues);
|
||||||
|
|
||||||
assert_eq!(&*format!("{}", p), "<pos>...");
|
assert_eq!(&*format!("{}", p), "<pos>...");
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ impl<'a> UsageParser<'a> {
|
||||||
};
|
};
|
||||||
if !arg.has_switch() && arg.is_set(ArgSettings::MultipleOccurrences) {
|
if !arg.has_switch() && arg.is_set(ArgSettings::MultipleOccurrences) {
|
||||||
// We had a positional and need to set mult vals too
|
// We had a positional and need to set mult vals too
|
||||||
arg.setb(ArgSettings::MultipleValues);
|
arg.set_mut(ArgSettings::MultipleValues);
|
||||||
}
|
}
|
||||||
debug!("UsageParser::parse: vals...{:?}", arg.val_names);
|
debug!("UsageParser::parse: vals...{:?}", arg.val_names);
|
||||||
arg
|
arg
|
||||||
|
@ -85,7 +85,7 @@ impl<'a> UsageParser<'a> {
|
||||||
== b'<'
|
== b'<'
|
||||||
&& !self.explicit_name_set
|
&& !self.explicit_name_set
|
||||||
{
|
{
|
||||||
arg.setb(ArgSettings::Required);
|
arg.set_mut(ArgSettings::Required);
|
||||||
}
|
}
|
||||||
self.pos += 1;
|
self.pos += 1;
|
||||||
self.stop_at(name_end);
|
self.stop_at(name_end);
|
||||||
|
@ -108,7 +108,7 @@ impl<'a> UsageParser<'a> {
|
||||||
let mut v = VecMap::new();
|
let mut v = VecMap::new();
|
||||||
v.insert(0, name);
|
v.insert(0, name);
|
||||||
arg.val_names = Some(v);
|
arg.val_names = Some(v);
|
||||||
arg.setb(ArgSettings::TakesValue);
|
arg.set_mut(ArgSettings::TakesValue);
|
||||||
}
|
}
|
||||||
self.prev = UsageToken::ValName;
|
self.prev = UsageToken::ValName;
|
||||||
}
|
}
|
||||||
|
@ -185,9 +185,9 @@ impl<'a> UsageParser<'a> {
|
||||||
if dot_counter == 3 {
|
if dot_counter == 3 {
|
||||||
debug!("UsageParser::multiple: setting multiple");
|
debug!("UsageParser::multiple: setting multiple");
|
||||||
if arg.is_set(ArgSettings::TakesValue) {
|
if arg.is_set(ArgSettings::TakesValue) {
|
||||||
arg.setb(ArgSettings::MultipleValues);
|
arg.set_mut(ArgSettings::MultipleValues);
|
||||||
}
|
}
|
||||||
arg.setb(ArgSettings::MultipleOccurrences);
|
arg.set_mut(ArgSettings::MultipleOccurrences);
|
||||||
self.prev = UsageToken::Multiple;
|
self.prev = UsageToken::Multiple;
|
||||||
self.pos += 1;
|
self.pos += 1;
|
||||||
break;
|
break;
|
||||||
|
@ -220,7 +220,7 @@ impl<'a> UsageParser<'a> {
|
||||||
"UsageParser::default: setting default...\"{}\"",
|
"UsageParser::default: setting default...\"{}\"",
|
||||||
&self.usage[self.start..self.pos]
|
&self.usage[self.start..self.pos]
|
||||||
);
|
);
|
||||||
arg.setb(ArgSettings::TakesValue);
|
arg.set_mut(ArgSettings::TakesValue);
|
||||||
arg.default_vals = Some(vec![std::ffi::OsStr::new(
|
arg.default_vals = Some(vec![std::ffi::OsStr::new(
|
||||||
&self.usage[self.start..self.pos],
|
&self.usage[self.start..self.pos],
|
||||||
)]);
|
)]);
|
||||||
|
|
|
@ -791,7 +791,7 @@ impl<'b, 'c, 'd, 'w> Help<'b, 'c, 'd, 'w> {
|
||||||
/// Writes default help for a Parser Object to the wrapped stream.
|
/// Writes default help for a Parser Object to the wrapped stream.
|
||||||
pub(crate) fn write_default_help(&mut self) -> ClapResult<()> {
|
pub(crate) fn write_default_help(&mut self) -> ClapResult<()> {
|
||||||
debug!("Help::write_default_help");
|
debug!("Help::write_default_help");
|
||||||
if let Some(h) = self.parser.app.pre_help {
|
if let Some(h) = self.parser.app.before_help {
|
||||||
self.write_before_after_help(h)?;
|
self.write_before_after_help(h)?;
|
||||||
self.none("\n\n")?;
|
self.none("\n\n")?;
|
||||||
}
|
}
|
||||||
|
@ -838,7 +838,7 @@ impl<'b, 'c, 'd, 'w> Help<'b, 'c, 'd, 'w> {
|
||||||
self.write_all_args()?;
|
self.write_all_args()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(h) = self.parser.app.more_help {
|
if let Some(h) = self.parser.app.after_help {
|
||||||
if flags || opts || pos || subcmds {
|
if flags || opts || pos || subcmds {
|
||||||
self.none("\n\n")?;
|
self.none("\n\n")?;
|
||||||
}
|
}
|
||||||
|
@ -1040,10 +1040,10 @@ impl<'b, 'c, 'd, 'w> Help<'b, 'c, 'd, 'w> {
|
||||||
self.write_subcommands(self.parser.app)?;
|
self.write_subcommands(self.parser.app)?;
|
||||||
}
|
}
|
||||||
b"after-help" => {
|
b"after-help" => {
|
||||||
self.none(self.parser.app.more_help.unwrap_or("unknown after-help"))?;
|
self.none(self.parser.app.after_help.unwrap_or("unknown after-help"))?;
|
||||||
}
|
}
|
||||||
b"before-help" => {
|
b"before-help" => {
|
||||||
self.none(self.parser.app.pre_help.unwrap_or("unknown before-help"))?;
|
self.none(self.parser.app.before_help.unwrap_or("unknown before-help"))?;
|
||||||
}
|
}
|
||||||
// Unknown tag, write it back.
|
// Unknown tag, write it back.
|
||||||
r => {
|
r => {
|
||||||
|
|
Loading…
Reference in a new issue