Merge pull request #2412 from clap-rs/docs

Apply cargo-intraconv
This commit is contained in:
Pavan Kumar Sunkara 2021-03-13 18:11:52 +05:30 committed by GitHub
commit dd352be191
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 330 additions and 430 deletions

View file

@ -16,7 +16,7 @@
#![doc(html_root_url = "https://docs.rs/clap_derive/3.0.0-beta.2")] #![doc(html_root_url = "https://docs.rs/clap_derive/3.0.0-beta.2")]
//! This crate is custom derive for clap. It should not be used //! This crate is custom derive for clap. It should not be used
//! directly. See [clap documentation](https://docs.rs/clap) //! directly. See [clap documentation](clap)
//! for the usage of `#[derive(Clap)]`. //! for the usage of `#[derive(Clap)]`.
#![forbid(unsafe_code)] #![forbid(unsafe_code)]

View file

@ -29,12 +29,12 @@ pub trait Generator {
/// ``` /// ```
fn file_name(name: &str) -> String; fn file_name(name: &str) -> String;
/// Generates output out of [`clap::App`](../clap/struct.App.html). /// Generates output out of [`clap::App`](super::clap::App).
/// ///
/// # Examples /// # Examples
/// ///
/// The following example generator displays the [`clap::App`](../clap/struct.App.html) /// The following example generator displays the [`clap::App`](super::clap::App)
/// as if it is printed using [`std::println`](https://doc.rust-lang.org/std/macro.println.html). /// as if it is printed using [`std::println`](std::println!).
/// ///
/// ``` /// ```
/// use std::{io::Write, fmt::write}; /// use std::{io::Write, fmt::write};
@ -72,7 +72,7 @@ pub trait Generator {
/// ///
/// **NOTE:** `path` should not contain the root `bin_name`. /// **NOTE:** `path` should not contain the root `bin_name`.
/// ///
/// [clap]: ../clap/struct.App.html /// [clap]: super::clap::App
fn find_subcommand_with_path<'help, 'app>( fn find_subcommand_with_path<'help, 'app>(
p: &'app App<'help>, p: &'app App<'help>,
path: Vec<&str>, path: Vec<&str>,
@ -86,7 +86,7 @@ pub trait Generator {
app app
} }
/// Gets subcommands of [`clap::App`](../clap/struct.App.html) in the form of `("name", "bin_name")`. /// Gets subcommands of [`clap::App`](super::clap::App) in the form of `("name", "bin_name")`.
/// ///
/// Subcommand `rustup toolchain install` would be converted to /// Subcommand `rustup toolchain install` would be converted to
/// `("install", "rustup toolchain install")`. /// `("install", "rustup toolchain install")`.
@ -115,8 +115,8 @@ pub trait Generator {
subcmds subcmds
} }
/// Gets all the short options, their visible aliases and flags of a [`clap::App`](../clap/struct.App.html). /// Gets all the short options, their visible aliases and flags of a [`clap::App`](super::clap::App).
/// Includes `h` and `V` depending on the [`clap::AppSettings`](../clap/enum.AppSettings.html). /// Includes `h` and `V` depending on the [`clap::AppSettings`](super::clap::AppSettings).
fn shorts_and_visible_aliases(p: &App) -> Vec<char> { fn shorts_and_visible_aliases(p: &App) -> Vec<char> {
debug!("shorts: name={}", p.get_name()); debug!("shorts: name={}", p.get_name());
@ -140,8 +140,8 @@ pub trait Generator {
.collect() .collect()
} }
/// Gets all the long options, their visible aliases and flags of a [`clap::App`](../clap/struct.App.html). /// Gets all the long options, their visible aliases and flags of a [`clap::App`](super::clap::App).
/// Includes `help` and `version` depending on the [`clap::AppSettings`](../clap/enum.AppSettings.html). /// Includes `help` and `version` depending on the [`clap::AppSettings`](super::clap::AppSettings).
fn longs_and_visible_aliases(p: &App) -> Vec<String> { fn longs_and_visible_aliases(p: &App) -> Vec<String> {
debug!("longs: name={}", p.get_name()); debug!("longs: name={}", p.get_name());
@ -170,8 +170,8 @@ pub trait Generator {
.collect() .collect()
} }
/// Gets all the flags of a [`clap::App`](../clap/struct.App.html). /// Gets all the flags of a [`clap::App`](super::clap::App).
/// Includes `help` and `version` depending on the [`clap::AppSettings`](../clap/enum.AppSettings.html). /// Includes `help` and `version` depending on the [`clap::AppSettings`](super::clap::AppSettings).
fn flags<'help>(p: &App<'help>) -> Vec<Arg<'help>> { fn flags<'help>(p: &App<'help>) -> Vec<Arg<'help>> {
debug!("flags: name={}", p.get_name()); debug!("flags: name={}", p.get_name());
p.get_flags().cloned().collect() p.get_flags().cloned().collect()

View file

@ -125,7 +125,7 @@ pub use shell::Shell;
/// Assuming we compiled with debug mode, it would be somewhere similar to /// Assuming we compiled with debug mode, it would be somewhere similar to
/// `<project>/target/debug/build/myapp-<hash>/out/myapp.bash`. /// `<project>/target/debug/build/myapp-<hash>/out/myapp.bash`.
/// ///
/// **NOTE:** Please look at the individual [generators](./generators/index.html) /// **NOTE:** Please look at the individual [generators]
/// to see the name of the files generated. /// to see the name of the files generated.
pub fn generate_to<G, S, T>(app: &mut clap::App, bin_name: S, out_dir: T) pub fn generate_to<G, S, T>(app: &mut clap::App, bin_name: S, out_dir: T)
where where
@ -152,7 +152,7 @@ where
/// ///
/// # Examples /// # Examples
/// ///
/// Assuming a separate `cli.rs` like the [example above](./fn.generate_to.html), /// Assuming a separate `cli.rs` like the [example above](generate_to()),
/// we can let users generate a completion script using a command: /// we can let users generate a completion script using a command:
/// ///
/// ```ignore /// ```ignore

View file

@ -59,7 +59,7 @@ use crate::{
/// ///
/// // Your program logic starts here... /// // Your program logic starts here...
/// ``` /// ```
/// [`App::get_matches`]: ./struct.App.html#method.get_matches /// [`App::get_matches`]: App::get_matches()
#[derive(Default, Debug, Clone, PartialEq, Eq)] #[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct App<'help> { pub struct App<'help> {
pub(crate) id: Id, pub(crate) id: Id,
@ -130,7 +130,7 @@ impl<'help> App<'help> {
/// Get the help message specified via [`App::about`]. /// Get the help message specified via [`App::about`].
/// ///
/// [`App::about`]: ./struct.App.html#method.about /// [`App::about`]: App::about()
#[inline] #[inline]
pub fn get_about(&self) -> Option<&str> { pub fn get_about(&self) -> Option<&str> {
self.about.as_deref() self.about.as_deref()
@ -313,9 +313,8 @@ impl<'help> App<'help> {
/// Returns `true` if the given [`AppSettings`] variant is currently set in /// Returns `true` if the given [`AppSettings`] variant is currently set in
/// this `App` (checks both [local] and [global settings]). /// this `App` (checks both [local] and [global settings]).
/// ///
/// [`AppSettings`]: ./enum.AppSettings.html /// [local]: App::setting()
/// [local]: ./struct.App.html#method.setting /// [global settings]: App::global_setting()
/// [global settings]: ./struct.App.html#method.global_setting
#[inline] #[inline]
pub fn is_set(&self, s: AppSettings) -> bool { pub fn is_set(&self, s: AppSettings) -> bool {
self.settings.is_set(s) || self.g_settings.is_set(s) self.settings.is_set(s) || self.g_settings.is_set(s)
@ -458,9 +457,9 @@ impl<'help> App<'help> {
/// .about("Does really amazing things for great people") /// .about("Does really amazing things for great people")
/// # ; /// # ;
/// ``` /// ```
/// [long format]: ./struct.App.html#method.long_about /// [long format]: App::long_about()
/// [short format]: ./struct.App.html#method.about /// [short format]: App::about()
/// [`App::about`]: ./struct.App.html#method.about /// [`App::about`]: App::about()
pub fn about<S: Into<&'help str>>(mut self, about: S) -> Self { pub fn about<S: Into<&'help str>>(mut self, about: S) -> Self {
self.about = Some(about.into()); self.about = Some(about.into());
self self
@ -492,9 +491,9 @@ impl<'help> App<'help> {
/// a few lines of text, but that's ok!") /// a few lines of text, but that's ok!")
/// # ; /// # ;
/// ``` /// ```
/// [long format]: ./struct.App.html#method.long_about /// [long format]: App::long_about()
/// [short format]: ./struct.App.html#method.about /// [short format]: App::about()
/// [`App::about`]: ./struct.App.html#method.about /// [`App::about`]: App::about()
pub fn long_about<S: Into<&'help str>>(mut self, about: S) -> Self { pub fn long_about<S: Into<&'help str>>(mut self, about: S) -> Self {
self.long_about = Some(about.into()); self.long_about = Some(about.into());
self self
@ -518,7 +517,6 @@ impl<'help> App<'help> {
/// // continued logic goes here, such as `app.get_matches()` etc. /// // continued logic goes here, such as `app.get_matches()` etc.
/// ``` /// ```
/// ///
/// [`crate_name!`]: ./macro.crate_name.html
pub fn name<S: Into<String>>(mut self, name: S) -> Self { pub fn name<S: Into<String>>(mut self, name: S) -> Self {
self.name = name.into(); self.name = name.into();
self self
@ -540,7 +538,7 @@ impl<'help> App<'help> {
/// # ; /// # ;
/// ``` /// ```
/// ///
/// [`App::after_help`]: ./struct.App.html#method.after_help /// [`App::after_help`]: App::after_help()
pub fn after_help<S: Into<&'help str>>(mut self, help: S) -> Self { pub fn after_help<S: Into<&'help str>>(mut self, help: S) -> Self {
self.after_help = Some(help.into()); self.after_help = Some(help.into());
self self
@ -563,7 +561,7 @@ impl<'help> App<'help> {
/// like, for real, be careful with this!") /// like, for real, be careful with this!")
/// # ; /// # ;
/// ``` /// ```
/// [`App::after_long_help`]: ./struct.App.html#method.after_long_help /// [`App::after_long_help`]: App::after_long_help()
pub fn after_long_help<S: Into<&'help str>>(mut self, help: S) -> Self { pub fn after_long_help<S: Into<&'help str>>(mut self, help: S) -> Self {
self.after_long_help = Some(help.into()); self.after_long_help = Some(help.into());
self self
@ -584,7 +582,7 @@ impl<'help> App<'help> {
/// .before_help("Some info I'd like to appear before the help info") /// .before_help("Some info I'd like to appear before the help info")
/// # ; /// # ;
/// ``` /// ```
/// [`App::before_help`]: ./struct.App.html#method.before_help /// [`App::before_help`]: App::before_help()
pub fn before_help<S: Into<&'help str>>(mut self, help: S) -> Self { pub fn before_help<S: Into<&'help str>>(mut self, help: S) -> Self {
self.before_help = Some(help.into()); self.before_help = Some(help.into());
self self
@ -605,7 +603,7 @@ impl<'help> App<'help> {
/// .before_long_help("Some verbose and long info I'd like to appear before the help info") /// .before_long_help("Some verbose and long info I'd like to appear before the help info")
/// # ; /// # ;
/// ``` /// ```
/// [`App::before_long_help`]: ./struct.App.html#method.before_long_help /// [`App::before_long_help`]: App::before_long_help()
pub fn before_long_help<S: Into<&'help str>>(mut self, help: S) -> Self { pub fn before_long_help<S: Into<&'help str>>(mut self, help: S) -> Self {
self.before_long_help = Some(help.into()); self.before_long_help = Some(help.into());
self self
@ -634,7 +632,7 @@ impl<'help> App<'help> {
/// let sync_matches = matches.subcommand_matches("sync").unwrap(); /// let sync_matches = matches.subcommand_matches("sync").unwrap();
/// assert!(sync_matches.is_present("search")); /// assert!(sync_matches.is_present("search"));
/// ``` /// ```
/// [`Arg::short`]: ./struct.Arg.html#method.short /// [`Arg::short`]: Arg::short()
pub fn short_flag(mut self, short: char) -> Self { pub fn short_flag(mut self, short: char) -> Self {
self.short_flag = Some(short); self.short_flag = Some(short);
self self
@ -670,7 +668,7 @@ impl<'help> App<'help> {
/// assert!(sync_matches.is_present("search")); /// assert!(sync_matches.is_present("search"));
/// ``` /// ```
/// ///
/// [`Arg::long`]: ./struct.Arg.html#method.long /// [`Arg::long`]: Arg::long()
pub fn long_flag(mut self, long: &'help str) -> Self { pub fn long_flag(mut self, long: &'help str) -> Self {
self.long_flag = Some(long.trim_start_matches(|c| c == '-')); self.long_flag = Some(long.trim_start_matches(|c| c == '-'));
self self
@ -701,7 +699,7 @@ impl<'help> App<'help> {
/// ``` /// ```
/// [`crate_version!`]: ./macro.crate_version!.html /// [`crate_version!`]: ./macro.crate_version!.html
/// [`examples/`]: https://github.com/clap-rs/clap/tree/master/examples /// [`examples/`]: https://github.com/clap-rs/clap/tree/master/examples
/// [`App::long_version`]: ./struct.App.html#method.long_version /// [`App::long_version`]: App::long_version()
pub fn version<S: Into<&'help str>>(mut self, ver: S) -> Self { pub fn version<S: Into<&'help str>>(mut self, ver: S) -> Self {
self.version = Some(ver.into()); self.version = Some(ver.into());
self self
@ -741,7 +739,7 @@ impl<'help> App<'help> {
/// ``` /// ```
/// [`crate_version!`]: ./macro.crate_version!.html /// [`crate_version!`]: ./macro.crate_version!.html
/// [`examples/`]: https://github.com/kbknapp/clap-rs/tree/master/examples /// [`examples/`]: https://github.com/kbknapp/clap-rs/tree/master/examples
/// [`App::version`]: ./struct.App.html#method.version /// [`App::version`]: App::version()
pub fn long_version<S: Into<&'help str>>(mut self, ver: S) -> Self { pub fn long_version<S: Into<&'help str>>(mut self, ver: S) -> Self {
self.long_version = Some(ver.into()); self.long_version = Some(ver.into());
self self
@ -787,7 +785,7 @@ impl<'help> App<'help> {
/// .override_usage("myapp [-clDas] <some_file>") /// .override_usage("myapp [-clDas] <some_file>")
/// # ; /// # ;
/// ``` /// ```
/// [`ArgMatches::usage`]: ./struct.ArgMatches.html#method.usage /// [`ArgMatches::usage`]: ArgMatches::usage()
pub fn override_usage<S: Into<&'help str>>(mut self, usage: S) -> Self { pub fn override_usage<S: Into<&'help str>>(mut self, usage: S) -> Self {
self.usage_str = Some(usage.into()); self.usage_str = Some(usage.into());
self self
@ -828,7 +826,7 @@ impl<'help> App<'help> {
/// work Do some work") /// work Do some work")
/// # ; /// # ;
/// ``` /// ```
/// [`Arg::override_help`]: ./struct.Arg.html#method.override_help /// [`Arg::override_help`]: Arg::override_help()
pub fn override_help<S: Into<&'help str>>(mut self, help: S) -> Self { pub fn override_help<S: Into<&'help str>>(mut self, help: S) -> Self {
self.help_str = Some(help.into()); self.help_str = Some(help.into());
self self
@ -875,13 +873,12 @@ impl<'help> App<'help> {
/// .help_template("{bin} ({version}) - {usage}") /// .help_template("{bin} ({version}) - {usage}")
/// # ; /// # ;
/// ``` /// ```
/// [`App::about`]: ./struct.App.html#method.about /// [`App::about`]: App::about()
/// [`App::long_about`]: ./struct.App.html#method.long_about /// [`App::long_about`]: App::long_about()
/// [`App::after_help`]: ./struct.App.html#method.after_help /// [`App::after_help`]: App::after_help()
/// [`App::after_long_help`]: ./struct.App.html#method.after_long_help /// [`App::after_long_help`]: App::after_long_help()
/// [`App::before_help`]: ./struct.App.html#method.before_help /// [`App::before_help`]: App::before_help()
/// [`App::before_long_help`]: ./struct.App.html#method.before_long_help /// [`App::before_long_help`]: App::before_long_help()
/// [`AppSettings::UnifiedHelpMessage`]: ./enum.AppSettings.html#variant.UnifiedHelpMessage
pub fn help_template<S: Into<&'help str>>(mut self, s: S) -> Self { pub fn help_template<S: Into<&'help str>>(mut self, s: S) -> Self {
self.template = Some(s.into()); self.template = Some(s.into());
self self
@ -900,7 +897,6 @@ impl<'help> App<'help> {
/// .setting(AppSettings::WaitOnError) /// .setting(AppSettings::WaitOnError)
/// # ; /// # ;
/// ``` /// ```
/// [`AppSettings`]: ./enum.AppSettings.html
#[inline] #[inline]
pub fn setting(mut self, setting: AppSettings) -> Self { pub fn setting(mut self, setting: AppSettings) -> Self {
self.settings.set(setting); self.settings.set(setting);
@ -919,7 +915,6 @@ impl<'help> App<'help> {
/// .unset_setting(AppSettings::ColorAuto) /// .unset_setting(AppSettings::ColorAuto)
/// # ; /// # ;
/// ``` /// ```
/// [`AppSettings`]: ./enum.AppSettings.html
#[inline] #[inline]
pub fn unset_setting(mut self, setting: AppSettings) -> Self { pub fn unset_setting(mut self, setting: AppSettings) -> Self {
self.settings.unset(setting); self.settings.unset(setting);
@ -941,7 +936,6 @@ impl<'help> App<'help> {
/// .global_setting(AppSettings::SubcommandRequired) /// .global_setting(AppSettings::SubcommandRequired)
/// # ; /// # ;
/// ``` /// ```
/// [`AppSettings`]: ./enum.AppSettings.html
#[inline] #[inline]
pub fn global_setting(mut self, setting: AppSettings) -> Self { pub fn global_setting(mut self, setting: AppSettings) -> Self {
self.settings.set(setting); self.settings.set(setting);
@ -965,8 +959,7 @@ impl<'help> App<'help> {
/// .unset_global_setting(AppSettings::ColorAuto) /// .unset_global_setting(AppSettings::ColorAuto)
/// # ; /// # ;
/// ``` /// ```
/// [`AppSettings`]: ./enum.AppSettings.html /// [global]: App::global_setting()
/// [global]: ./struct.App.html#method.global_setting
#[inline] #[inline]
pub fn unset_global_setting(mut self, setting: AppSettings) -> Self { pub fn unset_global_setting(mut self, setting: AppSettings) -> Self {
self.settings.unset(setting); self.settings.unset(setting);
@ -1056,7 +1049,7 @@ impl<'help> App<'help> {
/// ) /// )
/// # ; /// # ;
/// ``` /// ```
/// [argument]: ./struct.Arg.html /// [argument]: Arg
pub fn arg<A: Into<Arg<'help>>>(mut self, a: A) -> Self { pub fn arg<A: Into<Arg<'help>>>(mut self, a: A) -> Self {
let mut arg = a.into(); let mut arg = a.into();
if let Some(help_heading) = self.current_help_heading { if let Some(help_heading) = self.current_help_heading {
@ -1074,9 +1067,9 @@ impl<'help> App<'help> {
/// This is useful if the default `FLAGS`, `OPTIONS`, or `ARGS` headings are /// This is useful if the default `FLAGS`, `OPTIONS`, or `ARGS` headings are
/// not specific enough for one's use case. /// not specific enough for one's use case.
/// ///
/// [`App::arg`]: ./struct.App.html#method.arg /// [`App::arg`]: App::arg()
/// [`App::help_heading`]: ./struct.App.html#method.help_heading /// [`App::help_heading`]: App::help_heading()
/// [`App::stop_custom_headings`]: ./struct.App.html#method.stop_custom_headings /// [`App::stop_custom_headings`]: App::stop_custom_headings()
#[inline] #[inline]
pub fn help_heading(mut self, heading: &'help str) -> Self { pub fn help_heading(mut self, heading: &'help str) -> Self {
self.current_help_heading = Some(heading); self.current_help_heading = Some(heading);
@ -1085,7 +1078,7 @@ impl<'help> App<'help> {
/// Stop using [custom argument headings] and return to default headings. /// Stop using [custom argument headings] and return to default headings.
/// ///
/// [custom argument headings]: ./struct.App.html#method.help_heading /// [custom argument headings]: App::help_heading()
#[inline] #[inline]
pub fn stop_custom_headings(mut self) -> Self { pub fn stop_custom_headings(mut self) -> Self {
self.current_help_heading = None; self.current_help_heading = None;
@ -1105,7 +1098,7 @@ impl<'help> App<'help> {
/// ]) /// ])
/// # ; /// # ;
/// ``` /// ```
/// [arguments]: ./struct.Arg.html /// [arguments]: Arg
pub fn args<I, T>(mut self, args: I) -> Self pub fn args<I, T>(mut self, args: I) -> Self
where where
I: IntoIterator<Item = T>, I: IntoIterator<Item = T>,
@ -1143,8 +1136,7 @@ impl<'help> App<'help> {
/// .get_matches_from(vec!["myprog", "do-stuff"]); /// .get_matches_from(vec!["myprog", "do-stuff"]);
/// assert_eq!(m.subcommand_name(), Some("test")); /// assert_eq!(m.subcommand_name(), Some("test"));
/// ``` /// ```
/// [`ArgMatches`]: ./struct.ArgMatches.html /// [`App::visible_alias`]: App::visible_alias()
/// [`App::visible_alias`]: ./struct.App.html#method.visible_alias
pub fn alias<S: Into<&'help str>>(mut self, name: S) -> Self { pub fn alias<S: Into<&'help str>>(mut self, name: S) -> Self {
self.aliases.push((name.into(), false)); self.aliases.push((name.into(), false));
self self
@ -1221,8 +1213,7 @@ impl<'help> App<'help> {
/// .get_matches_from(vec!["myprog", "do-tests"]); /// .get_matches_from(vec!["myprog", "do-tests"]);
/// assert_eq!(m.subcommand_name(), Some("test")); /// assert_eq!(m.subcommand_name(), Some("test"));
/// ``` /// ```
/// [`ArgMatches`]: ./struct.ArgMatches.html /// [`App::visible_aliases`]: App::visible_aliases()
/// [`App::visible_aliases`]: ./struct.App.html#method.visible_aliases
pub fn aliases(mut self, names: &[&'help str]) -> Self { pub fn aliases(mut self, names: &[&'help str]) -> Self {
self.aliases.extend(names.iter().map(|n| (*n, false))); self.aliases.extend(names.iter().map(|n| (*n, false)));
self self
@ -1308,8 +1299,7 @@ impl<'help> App<'help> {
/// .get_matches_from(vec!["myprog", "do-stuff"]); /// .get_matches_from(vec!["myprog", "do-stuff"]);
/// assert_eq!(m.subcommand_name(), Some("test")); /// assert_eq!(m.subcommand_name(), Some("test"));
/// ``` /// ```
/// [`ArgMatches`]: ./struct.ArgMatches.html /// [`App::alias`]: App::alias()
/// [`App::alias`]: ./struct.App.html#method.alias
pub fn visible_alias<S: Into<&'help str>>(mut self, name: S) -> Self { pub fn visible_alias<S: Into<&'help str>>(mut self, name: S) -> Self {
self.aliases.push((name.into(), true)); self.aliases.push((name.into(), true));
self self
@ -1328,7 +1318,7 @@ impl<'help> App<'help> {
/// .get_matches_from(vec!["myprog", "-d"]); /// .get_matches_from(vec!["myprog", "-d"]);
/// assert_eq!(m.subcommand_name(), Some("test")); /// assert_eq!(m.subcommand_name(), Some("test"));
/// ``` /// ```
/// [`App::short_flag_alias`]: ./struct.App.html#method.short_flag_alias /// [`App::short_flag_alias`]: App::short_flag_alias()
pub fn visible_short_flag_alias(mut self, name: char) -> Self { pub fn visible_short_flag_alias(mut self, name: char) -> Self {
if name == '-' { if name == '-' {
panic!("short alias name cannot be `-`"); panic!("short alias name cannot be `-`");
@ -1350,7 +1340,7 @@ impl<'help> App<'help> {
/// .get_matches_from(vec!["myprog", "--testing"]); /// .get_matches_from(vec!["myprog", "--testing"]);
/// assert_eq!(m.subcommand_name(), Some("test")); /// assert_eq!(m.subcommand_name(), Some("test"));
/// ``` /// ```
/// [`App::long_flag_alias`]: ./struct.App.html#method.long_flag_alias /// [`App::long_flag_alias`]: App::long_flag_alias()
pub fn visible_long_flag_alias(mut self, name: &'help str) -> Self { pub fn visible_long_flag_alias(mut self, name: &'help str) -> Self {
self.long_flag_aliases.push((name, true)); self.long_flag_aliases.push((name, true));
self self
@ -1381,8 +1371,7 @@ impl<'help> App<'help> {
/// .get_matches_from(vec!["myprog", "do-stuff"]); /// .get_matches_from(vec!["myprog", "do-stuff"]);
/// assert_eq!(m.subcommand_name(), Some("test")); /// assert_eq!(m.subcommand_name(), Some("test"));
/// ``` /// ```
/// [`ArgMatches`]: ./struct.ArgMatches.html /// [`App::alias`]: App::alias()
/// [`App::alias`]: ./struct.App.html#method.alias
pub fn visible_aliases(mut self, names: &[&'help str]) -> Self { pub fn visible_aliases(mut self, names: &[&'help str]) -> Self {
self.aliases.extend(names.iter().map(|n| (*n, true))); self.aliases.extend(names.iter().map(|n| (*n, true)));
self self
@ -1401,7 +1390,7 @@ impl<'help> App<'help> {
/// .get_matches_from(vec!["myprog", "-t"]); /// .get_matches_from(vec!["myprog", "-t"]);
/// assert_eq!(m.subcommand_name(), Some("test")); /// assert_eq!(m.subcommand_name(), Some("test"));
/// ``` /// ```
/// [`App::short_flag_aliases`]: ./struct.App.html#method.short_flag_aliases /// [`App::short_flag_aliases`]: App::short_flag_aliases()
pub fn visible_short_flag_aliases(mut self, names: &[char]) -> Self { pub fn visible_short_flag_aliases(mut self, names: &[char]) -> Self {
for s in names { for s in names {
if s == &'-' { if s == &'-' {
@ -1425,7 +1414,7 @@ impl<'help> App<'help> {
/// .get_matches_from(vec!["myprog", "--testing"]); /// .get_matches_from(vec!["myprog", "--testing"]);
/// assert_eq!(m.subcommand_name(), Some("test")); /// assert_eq!(m.subcommand_name(), Some("test"));
/// ``` /// ```
/// [`App::long_flag_aliases`]: ./struct.App.html#method.long_flag_aliases /// [`App::long_flag_aliases`]: App::long_flag_aliases()
pub fn visible_long_flag_aliases(mut self, names: &[&'help str]) -> Self { pub fn visible_long_flag_aliases(mut self, names: &[&'help str]) -> Self {
for s in names { for s in names {
self.long_flag_aliases.push((s, true)); self.long_flag_aliases.push((s, true));
@ -1535,7 +1524,7 @@ impl<'help> App<'help> {
/// assert_eq!(m.value_of("format"), Some("json")); /// assert_eq!(m.value_of("format"), Some("json"));
/// ``` /// ```
/// ///
/// [`App::replace`]: ./struct.App.html#method.replace /// [`App::replace`]: App::replace()
#[inline] #[inline]
pub fn replace(mut self, name: &'help str, target: &'help [&'help str]) -> Self { pub fn replace(mut self, name: &'help str, target: &'help [&'help str]) -> Self {
self.replacers.insert(name, target); self.replacers.insert(name, target);
@ -1574,7 +1563,6 @@ impl<'help> App<'help> {
/// .required(true)) /// .required(true))
/// # ; /// # ;
/// ``` /// ```
/// [`ArgGroup`]: ./struct.ArgGroup.html
#[inline] #[inline]
pub fn group<G: Into<ArgGroup<'help>>>(mut self, group: G) -> Self { pub fn group<G: Into<ArgGroup<'help>>>(mut self, group: G) -> Self {
self.groups.push(group.into()); self.groups.push(group.into());
@ -1603,8 +1591,6 @@ impl<'help> App<'help> {
/// ]) /// ])
/// # ; /// # ;
/// ``` /// ```
/// [`ArgGroup`]: ./struct.ArgGroup.html
/// [`App`]: ./struct.App.html
pub fn groups<I, T>(mut self, groups: I) -> Self pub fn groups<I, T>(mut self, groups: I) -> Self
where where
I: IntoIterator<Item = T>, I: IntoIterator<Item = T>,
@ -1631,7 +1617,6 @@ impl<'help> App<'help> {
/// .arg("<config> 'Required configuration file to use'")) /// .arg("<config> 'Required configuration file to use'"))
/// # ; /// # ;
/// ``` /// ```
/// [`App`]: ./struct.App.html
#[inline] #[inline]
pub fn subcommand<S: Into<App<'help>>>(mut self, subcmd: S) -> Self { pub fn subcommand<S: Into<App<'help>>>(mut self, subcmd: S) -> Self {
self.subcommands.push(subcmd.into()); self.subcommands.push(subcmd.into());
@ -1652,8 +1637,7 @@ impl<'help> App<'help> {
/// App::new("debug").about("Controls debug functionality")]) /// App::new("debug").about("Controls debug functionality")])
/// # ; /// # ;
/// ``` /// ```
/// [`App`]: ./struct.App.html /// [`IntoIterator`]: std::iter::IntoIterator
/// [`IntoIterator`]: https://doc.rust-lang.org/std/iter/trait.IntoIterator.html
pub fn subcommands<I, T>(mut self, subcmds: I) -> Self pub fn subcommands<I, T>(mut self, subcmds: I) -> Self
where where
I: IntoIterator<Item = T>, I: IntoIterator<Item = T>,
@ -1739,8 +1723,6 @@ impl<'help> App<'help> {
/// let res = app.try_get_matches_from_mut(vec!["foo", "-B"]); /// let res = app.try_get_matches_from_mut(vec!["foo", "-B"]);
/// assert!(res.is_ok()); /// assert!(res.is_ok());
/// ``` /// ```
/// [`Arg`]: ./struct.Arg.html
/// [`App`]: ./struct.App.html
pub fn mut_arg<T, F>(mut self, arg_id: T, f: F) -> Self pub fn mut_arg<T, F>(mut self, arg_id: T, f: F) -> Self
where where
F: FnOnce(Arg<'help>) -> Arg<'help>, F: FnOnce(Arg<'help>) -> Arg<'help>,
@ -1776,10 +1758,10 @@ impl<'help> App<'help> {
/// let mut app = App::new("myprog"); /// let mut app = App::new("myprog");
/// app.print_help(); /// app.print_help();
/// ``` /// ```
/// [`io::stdout()`]: https://doc.rust-lang.org/std/io/fn.stdout.html /// [`io::stdout()`]: std::io::stdout()
/// [`BufWriter`]: https://doc.rust-lang.org/std/io/struct.BufWriter.html /// [`BufWriter`]: std::io::BufWriter
/// [`-h` (short)]: ./struct.Arg.html#method.about /// [`-h` (short)]: Arg::about()
/// [`--help` (long)]: ./struct.Arg.html#method.long_about /// [`--help` (long)]: Arg::long_about()
pub fn print_help(&mut self) -> io::Result<()> { pub fn print_help(&mut self) -> io::Result<()> {
self._build(); self._build();
@ -1802,10 +1784,10 @@ impl<'help> App<'help> {
/// let mut app = App::new("myprog"); /// let mut app = App::new("myprog");
/// app.print_long_help(); /// app.print_long_help();
/// ``` /// ```
/// [`io::stdout()`]: https://doc.rust-lang.org/std/io/fn.stdout.html /// [`io::stdout()`]: std::io::stdout()
/// [`BufWriter`]: https://doc.rust-lang.org/std/io/struct.BufWriter.html /// [`BufWriter`]: std::io::BufWriter
/// [`-h` (short)]: ./struct.Arg.html#method.about /// [`-h` (short)]: Arg::about()
/// [`--help` (long)]: ./struct.Arg.html#method.long_about /// [`--help` (long)]: Arg::long_about()
pub fn print_long_help(&mut self) -> io::Result<()> { pub fn print_long_help(&mut self) -> io::Result<()> {
self._build(); self._build();
@ -1830,9 +1812,9 @@ impl<'help> App<'help> {
/// let mut out = io::stdout(); /// let mut out = io::stdout();
/// app.write_help(&mut out).expect("failed to write to stdout"); /// app.write_help(&mut out).expect("failed to write to stdout");
/// ``` /// ```
/// [`io::Write`]: https://doc.rust-lang.org/std/io/trait.Write.html /// [`io::Write`]: std::io::Write
/// [`-h` (short)]: ./struct.Arg.html#method.about /// [`-h` (short)]: Arg::about()
/// [`--help` (long)]: ./struct.Arg.html#method.long_about /// [`--help` (long)]: Arg::long_about()
pub fn write_help<W: Write>(&mut self, w: &mut W) -> io::Result<()> { pub fn write_help<W: Write>(&mut self, w: &mut W) -> io::Result<()> {
self._build(); self._build();
@ -1856,9 +1838,9 @@ impl<'help> App<'help> {
/// let mut out = io::stdout(); /// let mut out = io::stdout();
/// app.write_long_help(&mut out).expect("failed to write to stdout"); /// app.write_long_help(&mut out).expect("failed to write to stdout");
/// ``` /// ```
/// [`io::Write`]: https://doc.rust-lang.org/std/io/trait.Write.html /// [`io::Write`]: std::io::Write
/// [`-h` (short)]: ./struct.Arg.html#method.about /// [`-h` (short)]: Arg::about()
/// [`--help` (long)]: ./struct.Arg.html#method.long_about /// [`--help` (long)]: Arg::long_about()
pub fn write_long_help<W: Write>(&mut self, w: &mut W) -> io::Result<()> { pub fn write_long_help<W: Write>(&mut self, w: &mut W) -> io::Result<()> {
self._build(); self._build();
@ -1884,9 +1866,9 @@ impl<'help> App<'help> {
/// let app = App::new("myprog"); /// let app = App::new("myprog");
/// println!("{}", app.render_version()); /// println!("{}", app.render_version());
/// ``` /// ```
/// [`io::Write`]: https://doc.rust-lang.org/std/io/trait.Write.html /// [`io::Write`]: std::io::Write
/// [`-V` (short)]: ./struct.App.html#method.version /// [`-V` (short)]: App::version()
/// [`--version` (long)]: ./struct.App.html#method.long_version /// [`--version` (long)]: App::long_version()
/// [ANSI escape codes]: https://en.wikipedia.org/wiki/ANSI_escape_code /// [ANSI escape codes]: https://en.wikipedia.org/wiki/ANSI_escape_code
pub fn render_version(&self) -> String { pub fn render_version(&self) -> String {
self._render_version(false) self._render_version(false)
@ -1909,9 +1891,9 @@ impl<'help> App<'help> {
/// let app = App::new("myprog"); /// let app = App::new("myprog");
/// println!("{}", app.render_long_version()); /// println!("{}", app.render_long_version());
/// ``` /// ```
/// [`io::Write`]: https://doc.rust-lang.org/std/io/trait.Write.html /// [`io::Write`]: std::io::Write
/// [`-V` (short)]: ./struct.App.html#method.version /// [`-V` (short)]: App::version()
/// [`--version` (long)]: ./struct.App.html#method.long_version /// [`--version` (long)]: App::long_version()
/// [ANSI escape codes]: https://en.wikipedia.org/wiki/ANSI_escape_code /// [ANSI escape codes]: https://en.wikipedia.org/wiki/ANSI_escape_code
pub fn render_long_version(&self) -> String { pub fn render_long_version(&self) -> String {
self._render_version(true) self._render_version(true)
@ -1941,7 +1923,7 @@ impl<'help> App<'help> {
/// // Args and options go here... /// // Args and options go here...
/// .get_matches(); /// .get_matches();
/// ``` /// ```
/// [`env::args_os`]: https://doc.rust-lang.org/std/env/fn.args_os.html /// [`env::args_os`]: std::env::args_os()
#[inline] #[inline]
pub fn get_matches(self) -> ArgMatches { pub fn get_matches(self) -> ArgMatches {
self.get_matches_from(&mut env::args_os()) self.get_matches_from(&mut env::args_os())
@ -1958,8 +1940,8 @@ impl<'help> App<'help> {
/// ; /// ;
/// let matches = app.get_matches_mut(); /// let matches = app.get_matches_mut();
/// ``` /// ```
/// [`env::args_os`]: https://doc.rust-lang.org/std/env/fn.args_os.html /// [`env::args_os`]: std::env::args_os()
/// [`App::get_matches`]: ./struct.App.html#method.get_matches /// [`App::get_matches`]: App::get_matches()
pub fn get_matches_mut(&mut self) -> ArgMatches { pub fn get_matches_mut(&mut self) -> ArgMatches {
self.try_get_matches_from_mut(&mut env::args_os()) self.try_get_matches_from_mut(&mut env::args_os())
.unwrap_or_else(|e| { .unwrap_or_else(|e| {
@ -1999,14 +1981,12 @@ impl<'help> App<'help> {
/// .try_get_matches() /// .try_get_matches()
/// .unwrap_or_else(|e| e.exit()); /// .unwrap_or_else(|e| e.exit());
/// ``` /// ```
/// [`env::args_os`]: https://doc.rust-lang.org/std/env/fn.args_os.html /// [`env::args_os`]: std::env::args_os()
/// [`ErrorKind::DisplayHelp`]: ./enum.ErrorKind.html#variant.DisplayHelp /// [`Error::exit`]: Error::exit()
/// [`ErrorKind::DisplayVersion`]: ./enum.ErrorKind.html#variant.DisplayVersion /// [`std::process::exit`]: std::process::exit()
/// [`Error::exit`]: ./struct.Error.html#method.exit /// [`clap::Result`]: Result
/// [`std::process::exit`]: https://doc.rust-lang.org/std/process/fn.exit.html /// [`clap::Error`]: Error
/// [`clap::Result`]: ./type.Result.html /// [`kind`]: Error
/// [`clap::Error`]: ./struct.Error.html
/// [`kind`]: ./struct.Error.html
#[inline] #[inline]
pub fn try_get_matches(self) -> ClapResult<ArgMatches> { pub fn try_get_matches(self) -> ClapResult<ArgMatches> {
// Start the parsing // Start the parsing
@ -2030,10 +2010,9 @@ impl<'help> App<'help> {
/// // Args and options go here... /// // Args and options go here...
/// .get_matches_from(arg_vec); /// .get_matches_from(arg_vec);
/// ``` /// ```
/// [`App::get_matches`]: ./struct.App.html#method.get_matches /// [`App::get_matches`]: App::get_matches()
/// [`clap::Result`]: ./type.Result.html /// [`clap::Result`]: Result
/// [`Vec`]: https://doc.rust-lang.org/std/vec/struct.Vec.html /// [`Vec`]: std::vec::Vec
/// [`AppSettings::NoBinaryName`]: ./enum.AppSettings.html#variant.NoBinaryName
pub fn get_matches_from<I, T>(mut self, itr: I) -> ArgMatches pub fn get_matches_from<I, T>(mut self, itr: I) -> ArgMatches
where where
I: IntoIterator<Item = T>, I: IntoIterator<Item = T>,
@ -2083,16 +2062,13 @@ impl<'help> App<'help> {
/// .try_get_matches_from(arg_vec) /// .try_get_matches_from(arg_vec)
/// .unwrap_or_else(|e| e.exit()); /// .unwrap_or_else(|e| e.exit());
/// ``` /// ```
/// [`App::get_matches_from`]: ./struct.App.html#method.get_matches_from /// [`App::get_matches_from`]: App::get_matches_from()
/// [`App::try_get_matches`]: ./struct.App.html#method.try_get_matches /// [`App::try_get_matches`]: App::try_get_matches()
/// [`ErrorKind::DisplayHelp`]: ./enum.ErrorKind.html#variant.DisplayHelp /// [`Error::exit`]: Error::exit()
/// [`ErrorKind::DisplayVersion`]: ./enum.ErrorKind.html#variant.DisplayVersion /// [`std::process::exit`]: std::process::exit()
/// [`Error::exit`]: ./struct.Error.html#method.exit /// [`clap::Error`]: Error
/// [`std::process::exit`]: https://doc.rust-lang.org/std/process/fn.exit.html /// [`Error::exit`]: Error::exit()
/// [`clap::Error`]: ./struct.Error.html /// [`kind`]: Error
/// [`Error::exit`]: ./struct.Error.html#method.exit
/// [`kind`]: ./struct.Error.html
/// [`AppSettings::NoBinaryName`]: ./enum.AppSettings.html#variant.NoBinaryName
pub fn try_get_matches_from<I, T>(mut self, itr: I) -> ClapResult<ArgMatches> pub fn try_get_matches_from<I, T>(mut self, itr: I) -> ClapResult<ArgMatches>
where where
I: IntoIterator<Item = T>, I: IntoIterator<Item = T>,
@ -2119,9 +2095,7 @@ impl<'help> App<'help> {
/// let matches = app.try_get_matches_from_mut(arg_vec) /// let matches = app.try_get_matches_from_mut(arg_vec)
/// .unwrap_or_else(|e| e.exit()); /// .unwrap_or_else(|e| e.exit());
/// ``` /// ```
/// [`App`]: ./struct.App.html /// [`App::try_get_matches_from`]: App::try_get_matches_from()
/// [`App::try_get_matches_from`]: ./struct.App.html#method.try_get_matches_from
/// [`AppSettings::NoBinaryName`]: ./enum.AppSettings.html#variant.NoBinaryName
pub fn try_get_matches_from_mut<I, T>(&mut self, itr: I) -> ClapResult<ArgMatches> pub fn try_get_matches_from_mut<I, T>(&mut self, itr: I) -> ClapResult<ArgMatches>
where where
I: IntoIterator<Item = T>, I: IntoIterator<Item = T>,

View file

@ -155,7 +155,6 @@ impl_settings! { AppSettings, AppFlags,
/// **NOTE:** When these settings are used, they apply only to current command, and are *not* /// **NOTE:** When these settings are used, they apply only to current command, and are *not*
/// propagated down or up through child or parent subcommands /// propagated down or up through child or parent subcommands
/// ///
/// [`App`]: ./struct.App.html
#[derive(Debug, PartialEq, Copy, Clone)] #[derive(Debug, PartialEq, Copy, Clone)]
pub enum AppSettings { pub enum AppSettings {
/// Specifies that any invalid UTF-8 code points should *not* be treated as an error. /// Specifies that any invalid UTF-8 code points should *not* be treated as an error.
@ -193,10 +192,10 @@ pub enum AppSettings {
/// let m = r.unwrap(); /// let m = r.unwrap();
/// assert_eq!(m.value_of_os("arg").unwrap().as_bytes(), &[0xe9]); /// assert_eq!(m.value_of_os("arg").unwrap().as_bytes(), &[0xe9]);
/// ``` /// ```
/// [`ArgMatches::os_value_of`]: ./struct.ArgMatches.html#method.os_value_of /// [`ArgMatches::os_value_of`]: ArgMatches::os_value_of()
/// [`ArgMatches::os_values_of`]: ./struct.ArgMatches.html#method.os_values_of /// [`ArgMatches::os_values_of`]: ArgMatches::os_values_of()
/// [`ArgMatches::lossy_value_of`]: ./struct.ArgMatches.html#method.lossy_value_of /// [`ArgMatches::lossy_value_of`]: ArgMatches::lossy_value_of()
/// [`ArgMatches::lossy_values_of`]: ./struct.ArgMatches.html#method.lossy_values_of /// [`ArgMatches::lossy_values_of`]: ArgMatches::lossy_values_of()
/// [``]: ./struct..html /// [``]: ./struct..html
AllowInvalidUtf8, AllowInvalidUtf8,
@ -222,13 +221,13 @@ pub enum AppSettings {
/// assert_eq!(m.value_of("neg"), Some("-20")); /// assert_eq!(m.value_of("neg"), Some("-20"));
/// # ; /// # ;
/// ``` /// ```
/// [`Arg::allow_hyphen_values`]: ./struct.Arg.html#method.allow_hyphen_values /// [`Arg::allow_hyphen_values`]: Arg::allow_hyphen_values()
AllowLeadingHyphen, AllowLeadingHyphen,
/// Specifies that all arguments override themselves. This is the equivalent to saying the `foo` /// Specifies that all arguments override themselves. This is the equivalent to saying the `foo`
/// arg using [`Arg::overrides_with("foo")`] for all defined arguments. /// arg using [`Arg::overrides_with("foo")`] for all defined arguments.
/// ///
/// [`Arg::overrides_with("foo")`]: ./struct.Arg.html#method.overrides_with /// [`Arg::overrides_with("foo")`]: Arg::overrides_with()
AllArgsOverrideSelf, AllArgsOverrideSelf,
/// Allows negative numbers to pass as values. This is similar to /// Allows negative numbers to pass as values. This is similar to
@ -250,7 +249,7 @@ pub enum AppSettings {
/// let m = res.unwrap(); /// let m = res.unwrap();
/// assert_eq!(m.value_of("num").unwrap(), "-20"); /// assert_eq!(m.value_of("num").unwrap(), "-20");
/// ``` /// ```
/// [`AllowLeadingHyphen`]: ./enum.AppSettings.html#variant.AllowLeadingHyphen /// [`AllowLeadingHyphen`]: AppSettings::AllowLeadingHyphen
AllowNegativeNumbers, AllowNegativeNumbers,
/// Allows one to implement two styles of CLIs where positionals can be used out of order. /// Allows one to implement two styles of CLIs where positionals can be used out of order.
@ -357,7 +356,7 @@ pub enum AppSettings {
/// assert_eq!(m.value_of("bar"), None); /// assert_eq!(m.value_of("bar"), None);
/// assert_eq!(m.values_of("baz").unwrap().collect::<Vec<_>>(), &["baz1", "baz2", "baz3"]); /// assert_eq!(m.values_of("baz").unwrap().collect::<Vec<_>>(), &["baz1", "baz2", "baz3"]);
/// ``` /// ```
/// [required]: ./struct.Arg.html#method.required /// [required]: Arg::required()
AllowMissingPositional, AllowMissingPositional,
/// Specifies that an unexpected positional argument, /// Specifies that an unexpected positional argument,
@ -391,9 +390,7 @@ pub enum AppSettings {
/// _ => {}, /// _ => {},
/// } /// }
/// ``` /// ```
/// [`ErrorKind::UnknownArgument`]: ./enum.ErrorKind.html#variant.UnknownArgument
/// [``]: ./struct..html /// [``]: ./struct..html
/// [`ArgMatches`]: ./struct.ArgMatches.html
AllowExternalSubcommands, AllowExternalSubcommands,
/// Specifies that use of a valid [argument] negates [subcomands] being used after. By default /// Specifies that use of a valid [argument] negates [subcomands] being used after. By default
@ -415,7 +412,7 @@ pub enum AppSettings {
/// # ; /// # ;
/// ``` /// ```
/// [subcommands]: ./struct..html /// [subcommands]: ./struct..html
/// [argument]: ./struct.Arg.html /// [argument]: Arg
ArgsNegateSubcommands, ArgsNegateSubcommands,
/// Specifies that the help text should be displayed (and then exit gracefully), /// Specifies that the help text should be displayed (and then exit gracefully),
@ -435,7 +432,7 @@ pub enum AppSettings {
/// # ; /// # ;
/// ``` /// ```
/// [``]: ./struct..html /// [``]: ./struct..html
/// [`Arg::default_value`]: ./struct.Arg.html#method.default_value /// [`Arg::default_value`]: Arg::default_value()
ArgRequiredElseHelp, ArgRequiredElseHelp,
/// Instructs the parser to stop when encountering a subcommand instead of greedily consuming /// Instructs the parser to stop when encountering a subcommand instead of greedily consuming
@ -596,8 +593,7 @@ pub enum AppSettings {
/// .setting(AppSettings::DontDelimitTrailingValues) /// .setting(AppSettings::DontDelimitTrailingValues)
/// .get_matches(); /// .get_matches();
/// ``` /// ```
/// [`AppSettings::TrailingVarArg`]: ./enum.AppSettings.html#variant.TrailingVarArg /// [`Arg::use_delimiter(false)`]: Arg::use_delimiter()
/// [`Arg::use_delimiter(false)`]: ./struct.Arg.html#method.use_delimiter
DontDelimitTrailingValues, DontDelimitTrailingValues,
/// Disables `-h` and `--help` [`App`] without affecting any of the [`SubCommand`]s /// Disables `-h` and `--help` [`App`] without affecting any of the [`SubCommand`]s
@ -627,8 +623,6 @@ pub enum AppSettings {
/// assert!(res.is_err()); /// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::DisplayHelp); /// assert_eq!(res.unwrap_err().kind, ErrorKind::DisplayHelp);
/// ``` /// ```
/// [`SubCommand`]: ./struct.SubCommand.html
/// [`App`]: ./struct.App.html
DisableHelpFlag, DisableHelpFlag,
/// Disables the `help` subcommand /// Disables the `help` subcommand
@ -682,7 +676,6 @@ pub enum AppSettings {
/// assert_eq!(res.unwrap_err().kind, ErrorKind::DisplayVersion); /// assert_eq!(res.unwrap_err().kind, ErrorKind::DisplayVersion);
/// ``` /// ```
/// [``]: ./struct..html /// [``]: ./struct..html
/// [`App`]: ./struct.App.html
DisableVersionFlag, DisableVersionFlag,
/// Disables `-V` and `--version` for all [`subcommand`]s of this [`App`] /// Disables `-V` and `--version` for all [`subcommand`]s of this [`App`]
@ -702,7 +695,6 @@ pub enum AppSettings {
/// assert!(res.is_err()); /// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::UnknownArgument); /// assert_eq!(res.unwrap_err().kind, ErrorKind::UnknownArgument);
/// ``` /// ```
/// [`App`]: ./struct.App.html
/// [``]: ./struct..html /// [``]: ./struct..html
DisableVersionForSubcommands, DisableVersionForSubcommands,
@ -812,9 +804,8 @@ pub enum AppSettings {
/// assert_eq!(m.subcommand_name(), Some("test")); /// assert_eq!(m.subcommand_name(), Some("test"));
/// ``` /// ```
/// [`subcommands`]: ./struct..html /// [`subcommands`]: ./struct..html
/// [positional/free arguments]: ./struct.Arg.html#method.index /// [positional/free arguments]: Arg::index()
/// [aliases]: ./struct.App.html#method.alias /// [aliases]: App::alias()
/// [`AppSettings::ArgsNegateSubcommands`]: ./enum.AppSettings.html#variant.ArgsNegateSubcommands
InferSubcommands, InferSubcommands,
/// Specifies that the parser should not assume the first argument passed is the binary name. /// Specifies that the parser should not assume the first argument passed is the binary name.
@ -888,7 +879,7 @@ pub enum AppSettings {
/// assert!(noerr.is_ok()); /// assert!(noerr.is_ok());
/// # ; /// # ;
/// ``` /// ```
/// [`Arg::required(true)`]: ./struct.Arg.html#method.required /// [`Arg::required(true)`]: Arg::required()
/// [``]: ./struct..html /// [``]: ./struct..html
SubcommandsNegateReqs, SubcommandsNegateReqs,
@ -911,8 +902,6 @@ pub enum AppSettings {
/// # ; /// # ;
/// ``` /// ```
/// [``]: ./struct..html /// [``]: ./struct..html
/// [`AppSettings::SubcommandRequired`]: ./enum.AppSettings.html#variant.SubcommandRequired
/// [`AppSettings::ArgRequiredElseHelp`]: ./enum.AppSettings.html#variant.ArgRequiredElseHelp
SubcommandRequiredElseHelp, SubcommandRequiredElseHelp,
/// Specifies that any invalid UTF-8 code points should be treated as an error and fail /// Specifies that any invalid UTF-8 code points should be treated as an error and fail
@ -945,7 +934,6 @@ pub enum AppSettings {
/// assert_eq!(m.unwrap_err().kind, ErrorKind::InvalidUtf8); /// assert_eq!(m.unwrap_err().kind, ErrorKind::InvalidUtf8);
/// ``` /// ```
/// [``]: ./struct..html /// [``]: ./struct..html
/// [`ErrorKind::InvalidUtf8`]: ./enum.ErrorKind.html#variant.InvalidUtf8
StrictUtf8, StrictUtf8,
/// Allows specifying that if no [``] is present at runtime, /// Allows specifying that if no [``] is present at runtime,
@ -990,7 +978,7 @@ pub enum AppSettings {
/// let trail: Vec<&str> = m.values_of("cmd").unwrap().collect(); /// let trail: Vec<&str> = m.values_of("cmd").unwrap().collect();
/// assert_eq!(trail, ["arg1", "-r", "val1"]); /// assert_eq!(trail, ["arg1", "-r", "val1"]);
/// ``` /// ```
/// [`Arg::multiple(true)`]: ./struct.Arg.html#method.multiple /// [`Arg::multiple(true)`]: Arg::multiple()
TrailingVarArg, TrailingVarArg,
/// Groups flags and options together, presenting a more unified help message /// Groups flags and options together, presenting a more unified help message

View file

@ -78,7 +78,6 @@ impl Default for ArgProvider {
/// // Using a usage string (setting a similar argument to the one above) /// // Using a usage string (setting a similar argument to the one above)
/// let input = Arg::from("-i, --input=[FILE] 'Provides an input file to the program'"); /// let input = Arg::from("-i, --input=[FILE] 'Provides an input file to the program'");
/// ``` /// ```
/// [`Arg`]: ./struct.Arg.html
#[allow(missing_debug_implementations)] #[allow(missing_debug_implementations)]
#[derive(Default, Clone)] #[derive(Default, Clone)]
pub struct Arg<'help> { pub struct Arg<'help> {
@ -296,8 +295,7 @@ impl<'help> Arg<'help> {
/// Arg::new("config") /// Arg::new("config")
/// # ; /// # ;
/// ``` /// ```
/// [`Arg::takes_value(true)`]: ./struct.Arg.html#method.takes_value /// [`Arg::takes_value(true)`]: Arg::takes_value()
/// [`Arg`]: ./struct.Arg.html
pub fn new<S: Into<&'help str>>(n: S) -> Self { pub fn new<S: Into<&'help str>>(n: S) -> Self {
let name = n.into(); let name = n.into();
Arg { Arg {
@ -346,7 +344,7 @@ impl<'help> Arg<'help> {
/// ///
/// assert!(m.is_present("config")); /// assert!(m.is_present("config"));
/// ``` /// ```
/// [`short`]: ./struct.Arg.html#method.short /// [`short`]: Arg::short()
#[inline] #[inline]
pub fn short(mut self, s: char) -> Self { pub fn short(mut self, s: char) -> Self {
if s == '-' { if s == '-' {
@ -418,7 +416,6 @@ impl<'help> Arg<'help> {
/// assert!(m.is_present("test")); /// assert!(m.is_present("test"));
/// assert_eq!(m.value_of("test"), Some("cool")); /// assert_eq!(m.value_of("test"), Some("cool"));
/// ``` /// ```
/// [`Arg`]: ./struct.Arg.html
pub fn alias<S: Into<&'help str>>(mut self, name: S) -> Self { pub fn alias<S: Into<&'help str>>(mut self, name: S) -> Self {
self.aliases.push((name.into(), false)); self.aliases.push((name.into(), false));
self self
@ -444,7 +441,6 @@ impl<'help> Arg<'help> {
/// assert!(m.is_present("test")); /// assert!(m.is_present("test"));
/// assert_eq!(m.value_of("test"), Some("cool")); /// assert_eq!(m.value_of("test"), Some("cool"));
/// ``` /// ```
/// [`Arg`]: ./struct.Arg.html
pub fn short_alias(mut self, name: char) -> Self { pub fn short_alias(mut self, name: char) -> Self {
if name == '-' { if name == '-' {
panic!("short alias name cannot be `-`"); panic!("short alias name cannot be `-`");
@ -474,7 +470,6 @@ impl<'help> Arg<'help> {
/// ]); /// ]);
/// assert!(m.is_present("test")); /// assert!(m.is_present("test"));
/// ``` /// ```
/// [`Arg`]: ./struct.Arg.html
pub fn aliases(mut self, names: &[&'help str]) -> Self { pub fn aliases(mut self, names: &[&'help str]) -> Self {
self.aliases.extend(names.iter().map(|&x| (x, false))); self.aliases.extend(names.iter().map(|&x| (x, false)));
self self
@ -500,7 +495,6 @@ impl<'help> Arg<'help> {
/// ]); /// ]);
/// assert!(m.is_present("test")); /// assert!(m.is_present("test"));
/// ``` /// ```
/// [`Arg`]: ./struct.Arg.html
pub fn short_aliases(mut self, names: &[char]) -> Self { pub fn short_aliases(mut self, names: &[char]) -> Self {
for s in names { for s in names {
if s == &'-' { if s == &'-' {
@ -529,8 +523,7 @@ impl<'help> Arg<'help> {
/// assert!(m.is_present("test")); /// assert!(m.is_present("test"));
/// assert_eq!(m.value_of("test"), Some("coffee")); /// assert_eq!(m.value_of("test"), Some("coffee"));
/// ``` /// ```
/// [`Arg`]: ./struct.Arg.html /// [`App::alias`]: Arg::alias()
/// [`App::alias`]: ./struct.Arg.html#method.alias
pub fn visible_alias<S: Into<&'help str>>(mut self, name: S) -> Self { pub fn visible_alias<S: Into<&'help str>>(mut self, name: S) -> Self {
self.aliases.push((name.into(), true)); self.aliases.push((name.into(), true));
self self
@ -554,8 +547,7 @@ impl<'help> Arg<'help> {
/// assert!(m.is_present("test")); /// assert!(m.is_present("test"));
/// assert_eq!(m.value_of("test"), Some("coffee")); /// assert_eq!(m.value_of("test"), Some("coffee"));
/// ``` /// ```
/// [`Arg`]: ./struct.Arg.html /// [`App::alias`]: Arg::short_alias()
/// [`App::alias`]: ./struct.Arg.html#method.short_alias
pub fn visible_short_alias(mut self, name: char) -> Self { pub fn visible_short_alias(mut self, name: char) -> Self {
if name == '-' { if name == '-' {
panic!("short alias name cannot be `-`"); panic!("short alias name cannot be `-`");
@ -581,8 +573,7 @@ impl<'help> Arg<'help> {
/// ]); /// ]);
/// assert!(m.is_present("test")); /// assert!(m.is_present("test"));
/// ``` /// ```
/// [`Arg`]: ./struct.Arg.html /// [`App::aliases`]: Arg::aliases()
/// [`App::aliases`]: ./struct.Arg.html#method.aliases
pub fn visible_aliases(mut self, names: &[&'help str]) -> Self { pub fn visible_aliases(mut self, names: &[&'help str]) -> Self {
self.aliases.extend(names.iter().map(|n| (*n, true))); self.aliases.extend(names.iter().map(|n| (*n, true)));
self self
@ -604,8 +595,7 @@ impl<'help> Arg<'help> {
/// ]); /// ]);
/// assert!(m.is_present("test")); /// assert!(m.is_present("test"));
/// ``` /// ```
/// [`Arg`]: ./struct.Arg.html /// [`App::aliases`]: Arg::short_aliases()
/// [`App::aliases`]: ./struct.Arg.html#method.short_aliases
pub fn visible_short_aliases(mut self, names: &[char]) -> Self { pub fn visible_short_aliases(mut self, names: &[char]) -> Self {
for n in names { for n in names {
if n == &'-' { if n == &'-' {
@ -665,7 +655,7 @@ impl<'help> Arg<'help> {
/// -h, --help Prints help information /// -h, --help Prints help information
/// -V, --version Prints version information /// -V, --version Prints version information
/// ``` /// ```
/// [`Arg::long_about`]: ./struct.Arg.html#method.long_about /// [`Arg::long_about`]: Arg::long_about()
#[inline] #[inline]
pub fn about(mut self, h: &'help str) -> Self { pub fn about(mut self, h: &'help str) -> Self {
self.about = Some(h); self.about = Some(h);
@ -737,7 +727,7 @@ impl<'help> Arg<'help> {
/// -V, --version /// -V, --version
/// Prints version information /// Prints version information
/// ``` /// ```
/// [`Arg::about`]: ./struct.Arg.html#method.about /// [`Arg::about`]: Arg::about()
#[inline] #[inline]
pub fn long_about(mut self, h: &'help str) -> Self { pub fn long_about(mut self, h: &'help str) -> Self {
self.long_about = Some(h); self.long_about = Some(h);
@ -795,7 +785,7 @@ impl<'help> Arg<'help> {
/// assert!(res.is_err()); /// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument); /// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// ``` /// ```
/// [required]: ./struct.Arg.html#method.required /// [required]: Arg::required()
pub fn required_unless_present<T: Key>(mut self, arg_id: T) -> Self { pub fn required_unless_present<T: Key>(mut self, arg_id: T) -> Self {
self.r_unless.push(arg_id.into()); self.r_unless.push(arg_id.into());
self self
@ -863,9 +853,9 @@ impl<'help> Arg<'help> {
/// assert!(res.is_err()); /// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument); /// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// ``` /// ```
/// [required]: ./struct.Arg.html#method.required /// [required]: Arg::required()
/// [`Arg::required_unless_present_any`]: ./struct.Arg.html#method.required_unless_present_any /// [`Arg::required_unless_present_any`]: Arg::required_unless_present_any()
/// [`Arg::required_unless_present_all(names)`]: ./struct.Arg.html#method.required_unless_present_all /// [`Arg::required_unless_present_all(names)`]: Arg::required_unless_present_all()
pub fn required_unless_present_all<T, I>(mut self, names: I) -> Self pub fn required_unless_present_all<T, I>(mut self, names: I) -> Self
where where
I: IntoIterator<Item = T>, I: IntoIterator<Item = T>,
@ -939,9 +929,9 @@ impl<'help> Arg<'help> {
/// assert!(res.is_err()); /// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument); /// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// ``` /// ```
/// [required]: ./struct.Arg.html#method.required /// [required]: Arg::required()
/// [`Arg::required_unless_present_any(names)`]: ./struct.Arg.html#method.required_unless_present_any /// [`Arg::required_unless_present_any(names)`]: Arg::required_unless_present_any()
/// [`Arg::required_unless_present_all`]: ./struct.Arg.html#method.required_unless_present_all /// [`Arg::required_unless_present_all`]: Arg::required_unless_present_all()
pub fn required_unless_present_any<T, I>(mut self, names: I) -> Self pub fn required_unless_present_any<T, I>(mut self, names: I) -> Self
where where
I: IntoIterator<Item = T>, I: IntoIterator<Item = T>,
@ -993,8 +983,8 @@ impl<'help> Arg<'help> {
/// assert_eq!(res.unwrap_err().kind, ErrorKind::ArgumentConflict); /// assert_eq!(res.unwrap_err().kind, ErrorKind::ArgumentConflict);
/// ``` /// ```
/// ///
/// [`Arg::conflicts_with_all(names)`]: ./struct.Arg.html#method.conflicts_with_all /// [`Arg::conflicts_with_all(names)`]: Arg::conflicts_with_all()
/// [`Arg::exclusive(true)`]: ./struct.Arg.html#method.exclusive /// [`Arg::exclusive(true)`]: Arg::exclusive()
pub fn conflicts_with<T: Key>(mut self, arg_id: T) -> Self { pub fn conflicts_with<T: Key>(mut self, arg_id: T) -> Self {
self.blacklist.push(arg_id.into()); self.blacklist.push(arg_id.into());
self self
@ -1045,8 +1035,8 @@ impl<'help> Arg<'help> {
/// assert!(res.is_err()); /// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::ArgumentConflict); /// assert_eq!(res.unwrap_err().kind, ErrorKind::ArgumentConflict);
/// ``` /// ```
/// [`Arg::conflicts_with`]: ./struct.Arg.html#method.conflicts_with /// [`Arg::conflicts_with`]: Arg::conflicts_with()
/// [`Arg::exclusive(true)`]: ./struct.Arg.html#method.exclusive /// [`Arg::exclusive(true)`]: Arg::exclusive()
pub fn conflicts_with_all(mut self, names: &[&str]) -> Self { pub fn conflicts_with_all(mut self, names: &[&str]) -> Self {
self.blacklist.extend(names.iter().map(Id::from)); self.blacklist.extend(names.iter().map(Id::from));
self self
@ -1197,8 +1187,8 @@ impl<'help> Arg<'help> {
/// assert_eq!(m.occurrences_of("opt"), 1); /// assert_eq!(m.occurrences_of("opt"), 1);
/// assert_eq!(m.values_of("opt").unwrap().collect::<Vec<_>>(), &["one,two"]); /// assert_eq!(m.values_of("opt").unwrap().collect::<Vec<_>>(), &["one,two"]);
/// ``` /// ```
/// [`Multiple*`]: ./enum.ArgSettings.html#variant.MultipleValues /// [`Multiple*`]: ArgSettings::MultipleValues
/// [`UseValueDelimiter`]: ./enum.ArgSettings.html#variant.UseValueDelimiter /// [`UseValueDelimiter`]: ArgSettings::UseValueDelimiter
pub fn overrides_with<T: Key>(mut self, arg_id: T) -> Self { pub fn overrides_with<T: Key>(mut self, arg_id: T) -> Self {
self.overrides.push(arg_id.into()); self.overrides.push(arg_id.into());
self self
@ -1288,9 +1278,9 @@ impl<'help> Arg<'help> {
/// assert!(res.is_err()); /// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument); /// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// ``` /// ```
/// [`Arg::requires(name)`]: ./struct.Arg.html#method.requires /// [`Arg::requires(name)`]: Arg::requires()
/// [Conflicting]: ./struct.Arg.html#method.conflicts_with /// [Conflicting]: Arg::conflicts_with()
/// [override]: ./struct.Arg.html#method.overrides_with /// [override]: Arg::overrides_with()
pub fn requires<T: Key>(mut self, arg_id: T) -> Self { pub fn requires<T: Key>(mut self, arg_id: T) -> Self {
self.requires.push((None, arg_id.into())); self.requires.push((None, arg_id.into()));
self self
@ -1355,9 +1345,9 @@ impl<'help> Arg<'help> {
/// assert!(res.is_err()); /// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument); /// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// ``` /// ```
/// [`Arg::requires(name)`]: ./struct.Arg.html#method.requires /// [`Arg::requires(name)`]: Arg::requires()
/// [Conflicting]: ./struct.Arg.html#method.conflicts_with /// [Conflicting]: Arg::conflicts_with()
/// [override]: ./struct.Arg.html#method.overrides_with /// [override]: Arg::overrides_with()
pub fn requires_if<T: Key>(mut self, val: &'help str, arg_id: T) -> Self { pub fn requires_if<T: Key>(mut self, val: &'help str, arg_id: T) -> Self {
self.requires.push((Some(val), arg_id.into())); self.requires.push((Some(val), arg_id.into()));
self self
@ -1411,9 +1401,9 @@ impl<'help> Arg<'help> {
/// assert!(res.is_err()); // We used --config=special.conf so --option <val> is required /// assert!(res.is_err()); // We used --config=special.conf so --option <val> is required
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument); /// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// ``` /// ```
/// [`Arg::requires(name)`]: ./struct.Arg.html#method.requires /// [`Arg::requires(name)`]: Arg::requires()
/// [Conflicting]: ./struct.Arg.html#method.conflicts_with /// [Conflicting]: Arg::conflicts_with()
/// [override]: ./struct.Arg.html#method.overrides_with /// [override]: Arg::overrides_with()
pub fn requires_ifs<T: Key>(mut self, ifs: &[(&'help str, T)]) -> Self { pub fn requires_ifs<T: Key>(mut self, ifs: &[(&'help str, T)]) -> Self {
self.requires self.requires
.extend(ifs.iter().map(|(val, arg)| (Some(*val), Id::from(arg)))); .extend(ifs.iter().map(|(val, arg)| (Some(*val), Id::from(arg))));
@ -1471,9 +1461,9 @@ impl<'help> Arg<'help> {
/// assert!(res.is_err()); /// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument); /// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// ``` /// ```
/// [`Arg::requires(name)`]: ./struct.Arg.html#method.requires /// [`Arg::requires(name)`]: Arg::requires()
/// [Conflicting]: ./struct.Arg.html#method.conflicts_with /// [Conflicting]: Arg::conflicts_with()
/// [required]: ./struct.Arg.html#method.required /// [required]: Arg::required()
pub fn required_if_eq<T: Key>(mut self, arg_id: T, val: &'help str) -> Self { pub fn required_if_eq<T: Key>(mut self, arg_id: T, val: &'help str) -> Self {
self.r_ifs.push((arg_id.into(), val)); self.r_ifs.push((arg_id.into(), val));
self self
@ -1556,9 +1546,9 @@ impl<'help> Arg<'help> {
/// assert!(res.is_err()); /// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument); /// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// ``` /// ```
/// [`Arg::requires(name)`]: ./struct.Arg.html#method.requires /// [`Arg::requires(name)`]: Arg::requires()
/// [Conflicting]: ./struct.Arg.html#method.conflicts_with /// [Conflicting]: Arg::conflicts_with()
/// [required]: ./struct.Arg.html#method.required /// [required]: Arg::required()
pub fn required_if_eq_any<T: Key>(mut self, ifs: &[(T, &'help str)]) -> Self { pub fn required_if_eq_any<T: Key>(mut self, ifs: &[(T, &'help str)]) -> Self {
self.r_ifs self.r_ifs
.extend(ifs.iter().map(|(id, val)| (Id::from_ref(id), *val))); .extend(ifs.iter().map(|(id, val)| (Id::from_ref(id), *val)));
@ -1642,7 +1632,7 @@ impl<'help> Arg<'help> {
/// assert!(res.is_err()); /// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument); /// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// ``` /// ```
/// [required]: ./struct.Arg.html#method.required /// [required]: Arg::required()
pub fn required_if_eq_all<T: Key>(mut self, ifs: &[(T, &'help str)]) -> Self { pub fn required_if_eq_all<T: Key>(mut self, ifs: &[(T, &'help str)]) -> Self {
self.r_ifs_all self.r_ifs_all
.extend(ifs.iter().map(|(id, val)| (Id::from_ref(id), *val))); .extend(ifs.iter().map(|(id, val)| (Id::from_ref(id), *val)));
@ -1708,8 +1698,8 @@ impl<'help> Arg<'help> {
/// // We didn't use output /// // We didn't use output
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument); /// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// ``` /// ```
/// [Conflicting]: ./struct.Arg.html#method.conflicts_with /// [Conflicting]: Arg::conflicts_with()
/// [override]: ./struct.Arg.html#method.overrides_with /// [override]: Arg::overrides_with()
pub fn requires_all<T: Key>(mut self, names: &[T]) -> Self { pub fn requires_all<T: Key>(mut self, names: &[T]) -> Self {
self.requires.extend(names.iter().map(|s| (None, s.into()))); self.requires.extend(names.iter().map(|s| (None, s.into())));
self self
@ -1760,10 +1750,9 @@ impl<'help> Arg<'help> {
/// assert_eq!(m.value_of("mode"), Some("fast")); // notice index(1) means "first positional" /// assert_eq!(m.value_of("mode"), Some("fast")); // notice index(1) means "first positional"
/// // *not* first argument /// // *not* first argument
/// ``` /// ```
/// [`Arg::short`]: ./struct.Arg.html#method.short /// [`Arg::short`]: Arg::short()
/// [`Arg::long`]: ./struct.Arg.html#method.long /// [`Arg::long`]: Arg::long()
/// [`Arg::multiple(true)`]: ./struct.Arg.html#method.multiple /// [`Arg::multiple(true)`]: Arg::multiple()
/// [`App`]: ./struct.App.html
/// [`panic!`]: https://doc.rust-lang.org/std/macro.panic!.html /// [`panic!`]: https://doc.rust-lang.org/std/macro.panic!.html
#[inline] #[inline]
pub fn index(mut self, idx: usize) -> Self { pub fn index(mut self, idx: usize) -> Self {
@ -1811,12 +1800,12 @@ impl<'help> Arg<'help> {
/// assert_eq!(&cmds, &["find", "-type", "f", "-name", "special"]); /// assert_eq!(&cmds, &["find", "-type", "f", "-name", "special"]);
/// assert_eq!(m.value_of("location"), Some("/home/clap")); /// assert_eq!(m.value_of("location"), Some("/home/clap"));
/// ``` /// ```
/// [options]: ./struct.Arg.html#method.takes_value /// [options]: Arg::takes_value()
/// [positional arguments]: ./struct.Arg.html#method.index /// [positional arguments]: Arg::index()
/// [`multiple(true)`]: ./struct.Arg.html#method.multiple /// [`multiple(true)`]: Arg::multiple()
/// [`min_values`]: ./struct.Arg.html#method.min_values /// [`min_values`]: Arg::min_values()
/// [`number_of_values`]: ./struct.Arg.html#method.number_of_values /// [`number_of_values`]: Arg::number_of_values()
/// [`max_values`]: ./struct.Arg.html#method.max_values /// [`max_values`]: Arg::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.terminator = Some(term); self.terminator = Some(term);
@ -1868,8 +1857,8 @@ impl<'help> Arg<'help> {
/// assert!(res.is_err()); /// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::InvalidValue); /// assert_eq!(res.unwrap_err().kind, ErrorKind::InvalidValue);
/// ``` /// ```
/// [options]: ./struct.Arg.html#method.takes_value /// [options]: Arg::takes_value()
/// [positional arguments]: ./struct.Arg.html#method.index /// [positional arguments]: Arg::index()
pub fn possible_values(mut self, names: &[&'help str]) -> Self { pub fn possible_values(mut self, names: &[&'help str]) -> Self {
self.possible_vals.extend(names); self.possible_vals.extend(names);
self.takes_value(true) self.takes_value(true)
@ -1926,8 +1915,8 @@ impl<'help> Arg<'help> {
/// assert!(res.is_err()); /// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::InvalidValue); /// assert_eq!(res.unwrap_err().kind, ErrorKind::InvalidValue);
/// ``` /// ```
/// [options]: ./struct.Arg.html#method.takes_value /// [options]: Arg::takes_value()
/// [positional arguments]: ./struct.Arg.html#method.index /// [positional arguments]: Arg::index()
pub fn possible_value(mut self, name: &'help str) -> Self { pub fn possible_value(mut self, name: &'help str) -> Self {
self.possible_vals.push(name); self.possible_vals.push(name);
self.takes_value(true) self.takes_value(true)
@ -1962,7 +1951,6 @@ impl<'help> Arg<'help> {
/// ]); /// ]);
/// assert!(m.is_present("mode")); /// assert!(m.is_present("mode"));
/// ``` /// ```
/// [`ArgGroup`]: ./struct.ArgGroup.html
pub fn group<T: Key>(mut self, group_id: T) -> Self { pub fn group<T: Key>(mut self, group_id: T) -> Self {
self.groups.push(group_id.into()); self.groups.push(group_id.into());
self self
@ -1998,7 +1986,6 @@ impl<'help> Arg<'help> {
/// assert!(m.is_present("mode")); /// assert!(m.is_present("mode"));
/// assert!(m.is_present("verbosity")); /// assert!(m.is_present("verbosity"));
/// ``` /// ```
/// [`ArgGroup`]: ./struct.ArgGroup.html
pub fn groups<T: Key>(mut self, group_ids: &[T]) -> Self { pub fn groups<T: Key>(mut self, group_ids: &[T]) -> Self {
self.groups.extend(group_ids.iter().map(Id::from)); self.groups.extend(group_ids.iter().map(Id::from));
self self
@ -2039,7 +2026,7 @@ impl<'help> Arg<'help> {
/// assert!(res.is_err()); /// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::WrongNumberOfValues); /// assert_eq!(res.unwrap_err().kind, ErrorKind::WrongNumberOfValues);
/// ``` /// ```
/// [`Arg::multiple(true)`]: ./struct.Arg.html#method.multiple /// [`Arg::multiple(true)`]: Arg::multiple()
#[inline] #[inline]
pub fn number_of_values(mut self, qty: usize) -> Self { pub fn number_of_values(mut self, qty: usize) -> Self {
self.num_vals = Some(qty); self.num_vals = Some(qty);
@ -2078,10 +2065,10 @@ impl<'help> Arg<'help> {
/// assert!(res.is_ok()); /// assert!(res.is_ok());
/// assert_eq!(res.unwrap().value_of("file"), Some("some@file")); /// assert_eq!(res.unwrap().value_of("file"), Some("some@file"));
/// ``` /// ```
/// [`String`]: https://doc.rust-lang.org/std/string/struct.String.html /// [`String`]: std::string::String
/// [`Result`]: https://doc.rust-lang.org/std/result/enum.Result.html /// [`Result`]: std::result::Result
/// [`Err(String)`]: https://doc.rust-lang.org/std/result/enum.Result.html#variant.Err /// [`Err(String)`]: std::result::Result::Err
/// [`Arc`]: https://doc.rust-lang.org/std/sync/struct.Arc.html /// [`Arc`]: std::sync::Arc
pub fn validator<F, O, E>(mut self, mut f: F) -> Self pub fn validator<F, O, E>(mut self, mut f: F) -> Self
where where
F: FnMut(&str) -> Result<O, E> + Send + 'help, F: FnMut(&str) -> Result<O, E> + Send + 'help,
@ -2117,12 +2104,12 @@ impl<'help> Arg<'help> {
/// assert!(res.is_ok()); /// assert!(res.is_ok());
/// assert_eq!(res.unwrap().value_of("file"), Some("Fish & chips")); /// assert_eq!(res.unwrap().value_of("file"), Some("Fish & chips"));
/// ``` /// ```
/// [`String`]: https://doc.rust-lang.org/std/string/struct.String.html /// [`String`]: std::string::String
/// [`OsStr`]: https://doc.rust-lang.org/std/ffi/struct.OsStr.html /// [`OsStr`]: std::ffi::OsStr
/// [`OsString`]: https://doc.rust-lang.org/std/ffi/struct.OsString.html /// [`OsString`]: std::ffi::OsString
/// [`Result`]: https://doc.rust-lang.org/std/result/enum.Result.html /// [`Result`]: std::result::Result
/// [`Err(String)`]: https://doc.rust-lang.org/std/result/enum.Result.html#variant.Err /// [`Err(String)`]: std::result::Result::Err
/// [`Rc`]: https://doc.rust-lang.org/std/rc/struct.Rc.html /// [`Rc`]: std::rc::Rc
pub fn validator_os<F, O, E>(mut self, mut f: F) -> Self pub fn validator_os<F, O, E>(mut self, mut f: F) -> Self
where where
F: FnMut(&OsStr) -> Result<O, E> + Send + 'help, F: FnMut(&OsStr) -> Result<O, E> + Send + 'help,
@ -2188,8 +2175,6 @@ impl<'help> Arg<'help> {
/// assert!(res.is_err()); /// assert!(res.is_err());
/// assert_eq!(res.err().unwrap().kind, ErrorKind::ValueValidation) /// assert_eq!(res.err().unwrap().kind, ErrorKind::ValueValidation)
/// ``` /// ```
/// [`Arg::validator()`]: ./struct.Arg.html#method.validator
/// [`RegexRef`]: ./struct.RegexRef.html
#[cfg(feature = "regex")] #[cfg(feature = "regex")]
pub fn validator_regex( pub fn validator_regex(
self, self,
@ -2261,7 +2246,7 @@ impl<'help> Arg<'help> {
/// assert!(res.is_err()); /// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::UnknownArgument); /// assert_eq!(res.unwrap_err().kind, ErrorKind::UnknownArgument);
/// ``` /// ```
/// [`Arg::multiple(true)`]: ./struct.Arg.html#method.multiple /// [`Arg::multiple(true)`]: Arg::multiple()
#[inline] #[inline]
pub fn max_values(mut self, qty: usize) -> Self { pub fn max_values(mut self, qty: usize) -> Self {
self.max_vals = Some(qty); self.max_vals = Some(qty);
@ -2324,7 +2309,7 @@ impl<'help> Arg<'help> {
/// assert!(res.is_err()); /// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::TooFewValues); /// assert_eq!(res.unwrap_err().kind, ErrorKind::TooFewValues);
/// ``` /// ```
/// [`Arg::multiple(true)`]: ./struct.Arg.html#method.multiple /// [`Arg::multiple(true)`]: Arg::multiple()
#[inline] #[inline]
pub fn min_values(mut self, qty: usize) -> Self { pub fn min_values(mut self, qty: usize) -> Self {
self.min_vals = Some(qty); self.min_vals = Some(qty);
@ -2352,8 +2337,8 @@ impl<'help> Arg<'help> {
/// ///
/// assert_eq!(m.values_of("config").unwrap().collect::<Vec<_>>(), ["val1", "val2", "val3"]) /// assert_eq!(m.values_of("config").unwrap().collect::<Vec<_>>(), ["val1", "val2", "val3"])
/// ``` /// ```
/// [`Arg::use_delimiter(true)`]: ./struct.Arg.html#method.use_delimiter /// [`Arg::use_delimiter(true)`]: Arg::use_delimiter()
/// [`Arg::takes_value(true)`]: ./struct.Arg.html#method.takes_value /// [`Arg::takes_value(true)`]: Arg::takes_value()
#[inline] #[inline]
pub fn value_delimiter(mut self, d: &str) -> Self { pub fn value_delimiter(mut self, d: &str) -> Self {
self.val_delim = Some( self.val_delim = Some(
@ -2419,10 +2404,10 @@ impl<'help> Arg<'help> {
/// OPTIONS: /// OPTIONS:
/// --io-files <INFILE> <OUTFILE> Some help text /// --io-files <INFILE> <OUTFILE> Some help text
/// ``` /// ```
/// [`Arg::next_line_help(true)`]: ./struct.Arg.html#method.next_line_help /// [`Arg::next_line_help(true)`]: Arg::next_line_help()
/// [`Arg::number_of_values`]: ./struct.Arg.html#method.number_of_values /// [`Arg::number_of_values`]: Arg::number_of_values()
/// [`Arg::takes_value(true)`]: ./struct.Arg.html#method.takes_value /// [`Arg::takes_value(true)`]: Arg::takes_value()
/// [`Arg::multiple(true)`]: ./struct.Arg.html#method.multiple /// [`Arg::multiple(true)`]: Arg::multiple()
pub fn value_names(mut self, names: &[&'help str]) -> Self { pub fn value_names(mut self, names: &[&'help str]) -> Self {
let mut i = self.val_names.len(); let mut i = self.val_names.len();
for s in names { for s in names {
@ -2477,9 +2462,9 @@ impl<'help> Arg<'help> {
/// OPTIONS: /// OPTIONS:
/// --config <FILE> Some help text /// --config <FILE> Some help text
/// ``` /// ```
/// [option]: ./struct.Arg.html#method.takes_value /// [option]: Arg::takes_value()
/// [positional]: ./struct.Arg.html#method.index /// [positional]: Arg::index()
/// [`Arg::takes_value(true)`]: ./struct.Arg.html#method.takes_value /// [`Arg::takes_value(true)`]: Arg::takes_value()
pub fn value_name(mut self, name: &'help str) -> Self { pub fn value_name(mut self, name: &'help str) -> Self {
let l = self.val_names.len(); let l = self.val_names.len();
self.val_names.insert(l, name); self.val_names.insert(l, name);
@ -2544,11 +2529,11 @@ impl<'help> Arg<'help> {
/// assert!(m.is_present("opt")); /// assert!(m.is_present("opt"));
/// assert_eq!(m.occurrences_of("opt"), 1); /// assert_eq!(m.occurrences_of("opt"), 1);
/// ``` /// ```
/// [`ArgMatches::occurrences_of`]: ./struct.ArgMatches.html#method.occurrences_of /// [`ArgMatches::occurrences_of`]: ArgMatches::occurrences_of()
/// [`ArgMatches::value_of`]: ./struct.ArgMatches.html#method.value_of /// [`ArgMatches::value_of`]: ArgMatches::value_of()
/// [`Arg::takes_value(true)`]: ./struct.Arg.html#method.takes_value /// [`Arg::takes_value(true)`]: Arg::takes_value()
/// [`ArgMatches::is_present`]: ./struct.ArgMatches.html#method.is_present /// [`ArgMatches::is_present`]: ArgMatches::is_present()
/// [`Arg::default_value_if`]: ./struct.Arg.html#method.default_value_if /// [`Arg::default_value_if`]: Arg::default_value_if()
#[inline] #[inline]
pub fn default_value(self, val: &'help str) -> Self { pub fn default_value(self, val: &'help str) -> Self {
self.default_values_os(&[OsStr::new(val)]) self.default_values_os(&[OsStr::new(val)])
@ -2557,8 +2542,8 @@ impl<'help> Arg<'help> {
/// Provides a default value in the exact same manner as [`Arg::default_value`] /// Provides a default value in the exact same manner as [`Arg::default_value`]
/// only using [`OsStr`]s instead. /// only using [`OsStr`]s instead.
/// ///
/// [`Arg::default_value`]: ./struct.Arg.html#method.default_value /// [`Arg::default_value`]: Arg::default_value()
/// [`OsStr`]: https://doc.rust-lang.org/std/ffi/struct.OsStr.html /// [`OsStr`]: std::ffi::OsStr
#[inline] #[inline]
pub fn default_value_os(self, val: &'help OsStr) -> Self { pub fn default_value_os(self, val: &'help OsStr) -> Self {
self.default_values_os(&[val]) self.default_values_os(&[val])
@ -2566,7 +2551,7 @@ impl<'help> Arg<'help> {
/// Like [`Arg::default_value`] but for args taking multiple values /// Like [`Arg::default_value`] but for args taking multiple values
/// ///
/// [`Arg::default_value`]: ./struct.Arg.html#method.default_value /// [`Arg::default_value`]: Arg::default_value()
#[inline] #[inline]
pub fn default_values(self, vals: &[&'help str]) -> Self { pub fn default_values(self, vals: &[&'help str]) -> Self {
let vals_vec: Vec<_> = vals.iter().map(|val| OsStr::new(*val)).collect(); let vals_vec: Vec<_> = vals.iter().map(|val| OsStr::new(*val)).collect();
@ -2576,8 +2561,8 @@ impl<'help> Arg<'help> {
/// Provides default values in the exact same manner as [`Arg::default_values`] /// Provides default values in the exact same manner as [`Arg::default_values`]
/// only using [`OsStr`]s instead. /// only using [`OsStr`]s instead.
/// ///
/// [`Arg::default_values`]: ./struct.Arg.html#method.default_values /// [`Arg::default_values`]: Arg::default_values()
/// [`OsStr`]: https://doc.rust-lang.org/std/ffi/struct.OsStr.html /// [`OsStr`]: std::ffi::OsStr
#[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.default_vals = vals.to_vec(); self.default_vals = vals.to_vec();
@ -2651,11 +2636,11 @@ impl<'help> Arg<'help> {
/// assert!(m.is_present("color")); /// assert!(m.is_present("color"));
/// assert_eq!(m.occurrences_of("color"), 1); /// assert_eq!(m.occurrences_of("color"), 1);
/// ``` /// ```
/// [`ArgMatches::occurrences_of`]: ./struct.ArgMatches.html#method.occurrences_of /// [`ArgMatches::occurrences_of`]: ArgMatches::occurrences_of()
/// [`ArgMatches::value_of`]: ./struct.ArgMatches.html#method.value_of /// [`ArgMatches::value_of`]: ArgMatches::value_of()
/// [`Arg::takes_value(true)`]: ./struct.Arg.html#method.takes_value /// [`Arg::takes_value(true)`]: Arg::takes_value()
/// [`ArgMatches::is_present`]: ./struct.ArgMatches.html#method.is_present /// [`ArgMatches::is_present`]: ArgMatches::is_present()
/// [`Arg::default_value`]: ./struct.Arg.html#method.default_value /// [`Arg::default_value`]: Arg::default_value()
#[inline] #[inline]
pub fn default_missing_value(self, val: &'help str) -> Self { pub fn default_missing_value(self, val: &'help str) -> Self {
self.default_missing_values_os(&[OsStr::new(val)]) self.default_missing_values_os(&[OsStr::new(val)])
@ -2664,8 +2649,8 @@ impl<'help> Arg<'help> {
/// Provides a default value in the exact same manner as [`Arg::default_missing_value`] /// Provides a default value in the exact same manner as [`Arg::default_missing_value`]
/// only using [`OsStr`]s instead. /// only using [`OsStr`]s instead.
/// ///
/// [`Arg::default_missing_value`]: ./struct.Arg.html#method.default_missing_value /// [`Arg::default_missing_value`]: Arg::default_missing_value()
/// [`OsStr`]: https://doc.rust-lang.org/std/ffi/struct.OsStr.html /// [`OsStr`]: std::ffi::OsStr
#[inline] #[inline]
pub fn default_missing_value_os(self, val: &'help OsStr) -> Self { pub fn default_missing_value_os(self, val: &'help OsStr) -> Self {
self.default_missing_values_os(&[val]) self.default_missing_values_os(&[val])
@ -2673,7 +2658,7 @@ impl<'help> Arg<'help> {
/// Like [`Arg::default_missing_value`] but for args taking multiple values /// Like [`Arg::default_missing_value`] but for args taking multiple values
/// ///
/// [`Arg::default_missing_value`]: ./struct.Arg.html#method.default_missing_value /// [`Arg::default_missing_value`]: Arg::default_missing_value()
#[inline] #[inline]
pub fn default_missing_values(self, vals: &[&'help str]) -> Self { pub fn default_missing_values(self, vals: &[&'help str]) -> Self {
let vals_vec: Vec<_> = vals.iter().map(|val| OsStr::new(*val)).collect(); let vals_vec: Vec<_> = vals.iter().map(|val| OsStr::new(*val)).collect();
@ -2683,8 +2668,8 @@ impl<'help> Arg<'help> {
/// Provides default values in the exact same manner as [`Arg::default_missing_values`] /// Provides default values in the exact same manner as [`Arg::default_missing_values`]
/// only using [`OsStr`]s instead. /// only using [`OsStr`]s instead.
/// ///
/// [`Arg::default_missing_values`]: ./struct.Arg.html#method.default_missing_values /// [`Arg::default_missing_values`]: Arg::default_missing_values()
/// [`OsStr`]: https://doc.rust-lang.org/std/ffi/struct.OsStr.html /// [`OsStr`]: std::ffi::OsStr
#[inline] #[inline]
pub fn default_missing_values_os(mut self, vals: &[&'help OsStr]) -> Self { pub fn default_missing_values_os(mut self, vals: &[&'help OsStr]) -> Self {
self.default_missing_vals = vals.to_vec(); self.default_missing_vals = vals.to_vec();
@ -2803,8 +2788,8 @@ impl<'help> Arg<'help> {
/// ///
/// assert_eq!(m.value_of("other"), None); /// assert_eq!(m.value_of("other"), None);
/// ``` /// ```
/// [`Arg::takes_value(true)`]: ./struct.Arg.html#method.takes_value /// [`Arg::takes_value(true)`]: Arg::takes_value()
/// [`Arg::default_value`]: ./struct.Arg.html#method.default_value /// [`Arg::default_value`]: Arg::default_value()
pub fn default_value_if<T: Key>( pub fn default_value_if<T: Key>(
self, self,
arg_id: T, arg_id: T,
@ -2817,8 +2802,8 @@ impl<'help> Arg<'help> {
/// Provides a conditional default value in the exact same manner as [`Arg::default_value_if`] /// Provides a conditional default value in the exact same manner as [`Arg::default_value_if`]
/// only using [`OsStr`]s instead. /// only using [`OsStr`]s instead.
/// ///
/// [`Arg::default_value_if`]: ./struct.Arg.html#method.default_value_if /// [`Arg::default_value_if`]: Arg::default_value_if()
/// [`OsStr`]: https://doc.rust-lang.org/std/ffi/struct.OsStr.html /// [`OsStr`]: std::ffi::OsStr
pub fn default_value_if_os<T: Key>( pub fn default_value_if_os<T: Key>(
mut self, mut self,
arg_id: T, arg_id: T,
@ -2913,8 +2898,8 @@ impl<'help> Arg<'help> {
/// ///
/// assert_eq!(m.value_of("other"), Some("default")); /// assert_eq!(m.value_of("other"), Some("default"));
/// ``` /// ```
/// [`Arg::takes_value(true)`]: ./struct.Arg.html#method.takes_value /// [`Arg::takes_value(true)`]: Arg::takes_value()
/// [`Arg::default_value_if`]: ./struct.Arg.html#method.default_value_if /// [`Arg::default_value_if`]: Arg::default_value_if()
pub fn default_value_ifs<T: Key>( pub fn default_value_ifs<T: Key>(
mut self, mut self,
ifs: &[(T, Option<&'help str>, Option<&'help str>)], ifs: &[(T, Option<&'help str>, Option<&'help str>)],
@ -2928,8 +2913,8 @@ impl<'help> Arg<'help> {
/// Provides multiple conditional default values in the exact same manner as /// Provides multiple conditional default values in the exact same manner as
/// [`Arg::default_value_ifs`] only using [`OsStr`]s instead. /// [`Arg::default_value_ifs`] only using [`OsStr`]s instead.
/// ///
/// [`Arg::default_value_ifs`]: ./struct.Arg.html#method.default_value_ifs /// [`Arg::default_value_ifs`]: Arg::default_value_ifs()
/// [`OsStr`]: https://doc.rust-lang.org/std/ffi/struct.OsStr.html /// [`OsStr`]: std::ffi::OsStr
pub fn default_value_ifs_os<T: Key>( pub fn default_value_ifs_os<T: Key>(
mut self, mut self,
ifs: &[(T, Option<&'help OsStr>, Option<&'help OsStr>)], ifs: &[(T, Option<&'help OsStr>, Option<&'help OsStr>)],
@ -3060,12 +3045,12 @@ impl<'help> Arg<'help> {
/// ///
/// assert_eq!(m.values_of("flag").unwrap().collect::<Vec<_>>(), vec!["env1", "env2"]); /// assert_eq!(m.values_of("flag").unwrap().collect::<Vec<_>>(), vec!["env1", "env2"]);
/// ``` /// ```
/// [`ArgMatches::occurrences_of`]: ./struct.ArgMatches.html#method.occurrences_of /// [`ArgMatches::occurrences_of`]: ArgMatches::occurrences_of()
/// [`ArgMatches::value_of`]: ./struct.ArgMatches.html#method.value_of /// [`ArgMatches::value_of`]: ArgMatches::value_of()
/// [`ArgMatches::is_present`]: ./struct.ArgMatches.html#method.is_present /// [`ArgMatches::is_present`]: ArgMatches::is_present()
/// [`Arg::takes_value(true)`]: ./struct.Arg.html#method.takes_value /// [`Arg::takes_value(true)`]: Arg::takes_value()
/// [`Arg::multiple(true)`]: ./struct.Arg.html#method.multiple /// [`Arg::multiple(true)`]: Arg::multiple()
/// [`Arg::use_delimiter(true)`]: ./struct.Arg.html#method.use_delimiter /// [`Arg::use_delimiter(true)`]: Arg::use_delimiter()
#[inline] #[inline]
pub fn env(self, name: &'help str) -> Self { pub fn env(self, name: &'help str) -> Self {
self.env_os(OsStr::new(name)) self.env_os(OsStr::new(name))
@ -3133,8 +3118,8 @@ impl<'help> Arg<'help> {
/// -O, --other-option <b> I should be first! /// -O, --other-option <b> I should be first!
/// -o, --long-option <a> Some help and text /// -o, --long-option <a> Some help and text
/// ``` /// ```
/// [positional arguments]: ./struct.Arg.html#method.index /// [positional arguments]: Arg::index()
/// [index]: ./struct.Arg.html#method.index /// [index]: Arg::index()
#[inline] #[inline]
pub fn display_order(mut self, ord: usize) -> Self { pub fn display_order(mut self, ord: usize) -> Self {
self.disp_ord = ord; self.disp_ord = ord;
@ -3213,13 +3198,8 @@ impl<'help> Arg<'help> {
/// assert!(res.is_err()); /// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::UnknownArgument); /// assert_eq!(res.unwrap_err().kind, ErrorKind::UnknownArgument);
/// ``` /// ```
/// [index]: ./struct.Arg.html#method.index /// [index]: Arg::index()
/// [`AppSettings::DontCollapseArgsInUsage`]: ./enum.AppSettings.html#variant.DontCollapseArgsInUsage /// [`UnknownArgument`]: ErrorKind::UnknownArgument
/// [`AppSettings::ArgsNegateSubcommands`]: ./enum.AppSettings.html#variant.ArgsNegateSubcommands
/// [`AppSettings::SubcommandsNegateReqs`]: ./enum.AppSettings.html#variant.SubcommandsNegateReqs
/// [`ArgSettings::Required`]: ./enum.ArgSettings.html#variant.Required
/// [`UnknownArgument`]: ./enum.ErrorKind.html#variant.UnknownArgument
/// [`ArgSettings::Last`]: ./enum.ArgSettings.html#variant.Last
#[inline] #[inline]
pub fn last(self, l: bool) -> Self { pub fn last(self, l: bool) -> Self {
if l { if l {
@ -3283,7 +3263,7 @@ impl<'help> Arg<'help> {
/// assert!(res.is_err()); /// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument); /// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// ``` /// ```
/// [`Required`]: ./enum.ArgSettings.html#variant.Required /// [`Required`]: ArgSettings::Required
#[inline] #[inline]
pub fn required(self, r: bool) -> Self { pub fn required(self, r: bool) -> Self {
if r { if r {
@ -3329,9 +3309,9 @@ impl<'help> Arg<'help> {
/// assert!(m.is_present("mode")); /// assert!(m.is_present("mode"));
/// assert_eq!(m.value_of("mode"), Some("fast")); /// assert_eq!(m.value_of("mode"), Some("fast"));
/// ``` /// ```
/// [`Arg::value_delimiter(char)`]: ./struct.Arg.html#method.value_delimiter /// [`Arg::value_delimiter(char)`]: Arg::value_delimiter()
/// [`Arg::unset_setting(ArgSettings::UseValueDelimiter)`]: ./enum.ArgSettings.html#variant.UseValueDelimiter /// [`Arg::unset_setting(ArgSettings::UseValueDelimiter)`]: ArgSettings::UseValueDelimiter
/// [multiple values]: ./enum.ArgSettings.html#variant.MultipleValues /// [multiple values]: ArgSettings::MultipleValues
#[inline] #[inline]
pub fn takes_value(self, tv: bool) -> Self { pub fn takes_value(self, tv: bool) -> Self {
if tv { if tv {
@ -3398,10 +3378,7 @@ impl<'help> Arg<'help> {
/// assert!(res.is_err()); /// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::UnknownArgument); /// assert_eq!(res.unwrap_err().kind, ErrorKind::UnknownArgument);
/// ``` /// ```
/// [`ArgSettings::AllowHyphenValues`]: ./enum.ArgSettings.html#variant.AllowHyphenValues /// [`Arg::number_of_values(1)`]: Arg::number_of_values()
/// [`ArgSettings::MultipleValues`]: ./enum.ArgSettings.html#variant.MultipleValues
/// [`ArgSettings::MultipleOccurrences`]: ./enum.ArgSettings.html#variant.MultipleOccurrences
/// [`Arg::number_of_values(1)`]: ./struct.Arg.html#method.number_of_values
#[inline] #[inline]
pub fn allow_hyphen_values(self, a: bool) -> Self { pub fn allow_hyphen_values(self, a: bool) -> Self {
if a { if a {
@ -3461,7 +3438,7 @@ impl<'help> Arg<'help> {
/// assert!(res.is_err()); /// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::NoEquals); /// assert_eq!(res.unwrap_err().kind, ErrorKind::NoEquals);
/// ``` /// ```
/// [`RequireEquals`]: ./enum.ArgSettings.html#variant.RequireEquals /// [`RequireEquals`]: ArgSettings::RequireEquals
#[inline] #[inline]
pub fn require_equals(self, r: bool) -> Self { pub fn require_equals(self, r: bool) -> Self {
if r { if r {
@ -3509,11 +3486,9 @@ impl<'help> Arg<'help> {
/// let sub_m = m.subcommand_matches("do-stuff").unwrap(); /// let sub_m = m.subcommand_matches("do-stuff").unwrap();
/// assert!(sub_m.is_present("verb")); /// assert!(sub_m.is_present("verb"));
/// ``` /// ```
/// [``]: ./struct.App.html#method.subcommand /// [``]: App::subcommand()
/// [required]: ./enum.ArgSettings.html#variant.Required /// [required]: ArgSettings::Required
/// [`ArgMatches`]: ./struct.ArgMatches.html /// [`ArgMatches::is_present("flag")`]: ArgMatches::is_present()
/// [`ArgMatches::is_present("flag")`]: ./struct.ArgMatches.html#method.is_present
/// [`Arg`]: ./struct.Arg.html
#[inline] #[inline]
pub fn global(mut self, g: bool) -> Self { pub fn global(mut self, g: bool) -> Self {
self.global = g; self.global = g;
@ -3593,8 +3568,6 @@ impl<'help> Arg<'help> {
/// assert!(delims.is_present("opt")); /// assert!(delims.is_present("opt"));
/// assert_eq!(delims.values_of("opt").unwrap().collect::<Vec<_>>(), ["val1", "val2", "val3"]); /// assert_eq!(delims.values_of("opt").unwrap().collect::<Vec<_>>(), ["val1", "val2", "val3"]);
/// ``` /// ```
/// [`ArgSettings::UseValueDelimiter`]: ./enum.ArgSettings.html#variant.UseValueDelimiter
/// [`ArgSettings::TakesValue`]: ./enum.ArgSettings.html#variant.TakesValue
#[inline] #[inline]
pub fn require_delimiter(self, d: bool) -> Self { pub fn require_delimiter(self, d: bool) -> Self {
if d { if d {
@ -3824,7 +3797,7 @@ impl<'help> Arg<'help> {
/// assert_eq!(nodelims.occurrences_of("option"), 1); /// assert_eq!(nodelims.occurrences_of("option"), 1);
/// assert_eq!(nodelims.value_of("option").unwrap(), "val1,val2,val3"); /// assert_eq!(nodelims.value_of("option").unwrap(), "val1,val2,val3");
/// ``` /// ```
/// [`Arg::value_delimiter`]: ./struct.Arg.html#method.value_delimiter /// [`Arg::value_delimiter`]: Arg::value_delimiter()
#[inline] #[inline]
pub fn use_delimiter(mut self, d: bool) -> Self { pub fn use_delimiter(mut self, d: bool) -> Self {
if d { if d {
@ -3960,7 +3933,6 @@ impl<'help> Arg<'help> {
/// help that makes more sense to be /// help that makes more sense to be
/// on a line after the option /// on a line after the option
/// ``` /// ```
/// [`AppSettings::NextLineHelp`]: ./enum.AppSettings.html#variant.NextLineHelp
#[inline] #[inline]
pub fn next_line_help(self, nlh: bool) -> Self { pub fn next_line_help(self, nlh: bool) -> Self {
if nlh { if nlh {
@ -4144,17 +4116,17 @@ impl<'help> Arg<'help> {
/// assert!(res.is_err()); /// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::UnknownArgument); /// assert_eq!(res.unwrap_err().kind, ErrorKind::UnknownArgument);
/// ``` /// ```
/// [option]: ./enum.ArgSettings.html#variant.TakesValue /// [option]: ArgSettings::TakesValue
/// [options]: ./enum.ArgSettings.html#variant.TakesValue /// [options]: ArgSettings::TakesValue
/// [subcommands]: ./struct.App.html#method.subcommand /// [subcommands]: App::subcommand()
/// [positionals]: ./struct.Arg.html#method.index /// [positionals]: Arg::index()
/// [`Arg::number_of_values(1)`]: ./struct.Arg.html#method.number_of_values /// [`Arg::number_of_values(1)`]: Arg::number_of_values()
/// [`MultipleOccurrences`]: ./enum.ArgSettings.html#variant.MultipleOccurrences /// [`MultipleOccurrences`]: ArgSettings::MultipleOccurrences
/// [`MultipleValues`]: ./enum.ArgSettings.html#variant.MultipleValues /// [`MultipleValues`]: ArgSettings::MultipleValues
/// [maximum number of values]: ./struct.Arg.html#method.max_values /// [maximum number of values]: Arg::max_values()
/// [specific number of values]: ./struct.Arg.html#method.number_of_values /// [specific number of values]: Arg::number_of_values()
/// [maximum]: ./struct.Arg.html#method.max_values /// [maximum]: Arg::max_values()
/// [specific]: ./struct.Arg.html#method.number_of_values /// [specific]: Arg::number_of_values()
#[inline] #[inline]
pub fn multiple(self, multi: bool) -> Self { pub fn multiple(self, multi: bool) -> Self {
self.multiple_occurrences(multi).multiple_values(multi) self.multiple_occurrences(multi).multiple_values(multi)
@ -4213,7 +4185,6 @@ impl<'help> Arg<'help> {
/// assert!(res.is_err()); /// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::EmptyValue); /// assert_eq!(res.unwrap_err().kind, ErrorKind::EmptyValue);
/// ``` /// ```
/// [`ArgSettings::TakesValue`]: ./enum.ArgSettings.html#variant.TakesValue
#[inline] #[inline]
pub fn forbid_empty_values(self, empty: bool) -> Self { pub fn forbid_empty_values(self, empty: bool) -> Self {
if empty { if empty {
@ -4284,17 +4255,17 @@ impl<'help> Arg<'help> {
/// let files: Vec<_> = m.values_of("file").unwrap().collect(); /// let files: Vec<_> = m.values_of("file").unwrap().collect();
/// assert_eq!(files, ["file1", "file2", "file3"]); /// assert_eq!(files, ["file1", "file2", "file3"]);
/// ``` /// ```
/// [option]: ./enum.ArgSettings.html#variant.TakesValue /// [option]: ArgSettings::TakesValue
/// [options]: ./enum.ArgSettings.html#variant.TakesValue /// [options]: ArgSettings::TakesValue
/// [subcommands]: ./struct.App.html#method.subcommand /// [subcommands]: App::subcommand()
/// [positionals]: ./struct.Arg.html#method.index /// [positionals]: Arg::index()
/// [`Arg::number_of_values(1)`]: ./struct.Arg.html#method.number_of_values /// [`Arg::number_of_values(1)`]: Arg::number_of_values()
/// [`MultipleOccurrences`]: ./enum.ArgSettings.html#variant.MultipleOccurrences /// [`MultipleOccurrences`]: ArgSettings::MultipleOccurrences
/// [`MultipleValues`]: ./enum.ArgSettings.html#variant.MultipleValues /// [`MultipleValues`]: ArgSettings::MultipleValues
/// [maximum number of values]: ./struct.Arg.html#method.max_values /// [maximum number of values]: Arg::max_values()
/// [specific number of values]: ./struct.Arg.html#method.number_of_values /// [specific number of values]: Arg::number_of_values()
/// [maximum]: ./struct.Arg.html#method.max_values /// [maximum]: Arg::max_values()
/// [specific]: ./struct.Arg.html#method.number_of_values /// [specific]: Arg::number_of_values()
#[inline] #[inline]
pub fn multiple_occurrences(self, multi: bool) -> Self { pub fn multiple_occurrences(self, multi: bool) -> Self {
if multi { if multi {
@ -4319,11 +4290,10 @@ impl<'help> Arg<'help> {
/// **NOTE:** Implicitly sets [`Arg::takes_value(true)`] [`Arg::multiple(true)`], [`Arg::allow_hyphen_values(true)`], and /// **NOTE:** Implicitly sets [`Arg::takes_value(true)`] [`Arg::multiple(true)`], [`Arg::allow_hyphen_values(true)`], and
/// [`Arg::last(true)`] when set to `true` /// [`Arg::last(true)`] when set to `true`
/// ///
/// [`Arg::takes_value(true)`]: ./struct.Arg.html#method.takes_value /// [`Arg::takes_value(true)`]: Arg::takes_value()
/// [`Arg::multiple(true)`]: ./struct.Arg.html#method.multiple /// [`Arg::multiple(true)`]: Arg::multiple()
/// [`Arg::allow_hyphen_values(true)`]: ./struct.Arg.html#method.allow_hyphen_values /// [`Arg::allow_hyphen_values(true)`]: Arg::allow_hyphen_values()
/// [`Arg::last(true)`]: ./struct.Arg.html#method.last /// [`Arg::last(true)`]: Arg::last()
/// [`AppSettings::TrailingVarArg`]: ./enum.AppSettings.html#variant.TrailingVarArg
#[inline] #[inline]
pub fn raw(self, raw: bool) -> Self { pub fn raw(self, raw: bool) -> Self {
self.takes_value(raw) self.takes_value(raw)
@ -4491,7 +4461,6 @@ impl<'help> Arg<'help> {
// @TODO @docs @v3-beta: write better docs as ArgSettings is now critical // @TODO @docs @v3-beta: write better docs as ArgSettings is now critical
/// Checks if one of the [`ArgSettings`] is set for the argument /// Checks if one of the [`ArgSettings`] is set for the argument
/// ///
/// [`ArgSettings`]: ./enum.ArgSettings.html
#[inline] #[inline]
pub fn is_set(&self, s: ArgSettings) -> bool { pub fn is_set(&self, s: ArgSettings) -> bool {
self.settings.is_set(s) self.settings.is_set(s)
@ -4510,7 +4479,6 @@ impl<'help> Arg<'help> {
/// .setting(ArgSettings::TakesValue) /// .setting(ArgSettings::TakesValue)
/// # ; /// # ;
/// ``` /// ```
/// [`ArgSettings`]: ./enum.ArgSettings.html
#[inline] #[inline]
pub fn setting(mut self, setting: ArgSettings) -> Self { pub fn setting(mut self, setting: ArgSettings) -> Self {
self.settings.set(setting); self.settings.set(setting);
@ -4529,7 +4497,6 @@ impl<'help> Arg<'help> {
/// .unset_setting(ArgSettings::Required) /// .unset_setting(ArgSettings::Required)
/// # ; /// # ;
/// ``` /// ```
/// [`ArgSettings`]: ./enum.ArgSettings.html
#[inline] #[inline]
pub fn unset_setting(mut self, setting: ArgSettings) -> Self { pub fn unset_setting(mut self, setting: ArgSettings) -> Self {
self.settings.unset(setting); self.settings.unset(setting);
@ -4660,7 +4627,6 @@ impl<'help> From<&'help Yaml> for Arg<'help> {
/// let yaml = load_yaml!("arg.yaml"); /// let yaml = load_yaml!("arg.yaml");
/// let arg = Arg::from(yaml); /// let arg = Arg::from(yaml);
/// ``` /// ```
/// [`Arg`]: ./struct.Arg.html
#[allow(clippy::cognitive_complexity)] #[allow(clippy::cognitive_complexity)]
fn from(y: &'help Yaml) -> Self { fn from(y: &'help Yaml) -> Self {
let y = y.as_hash().unwrap(); let y = y.as_hash().unwrap();

View file

@ -8,7 +8,7 @@ use std::borrow::Cow;
/// ///
/// Essentially a [`Cow`] wrapper with custom convenience traits. /// Essentially a [`Cow`] wrapper with custom convenience traits.
/// ///
/// [`Cow`]: https://doc.rust-lang.org/std/borrow/enum.Cow.html /// [`Cow`]: std::borrow::Cow
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct RegexRef<'a>(Cow<'a, Regex>); pub struct RegexRef<'a>(Cow<'a, Regex>);

View file

@ -68,10 +68,9 @@ impl Default for ArgFlags {
/// methods [`Arg::setting`], [`Arg::unset_setting`], and [`Arg::is_set`]. This is what the /// methods [`Arg::setting`], [`Arg::unset_setting`], and [`Arg::is_set`]. This is what the
/// [`Arg`] methods which accept a `bool` use internally. /// [`Arg`] methods which accept a `bool` use internally.
/// ///
/// [`Arg`]: ./struct.Arg.html /// [`Arg::setting`]: Arg::setting()
/// [`Arg::setting`]: ./struct.Arg.html#method.setting /// [`Arg::unset_setting`]: Arg::unset_setting()
/// [`Arg::unset_setting`]: ./struct.Arg.html#method.unset_setting /// [`Arg::is_set`]: Arg::is_set()
/// [`Arg::is_set`]: ./struct.Arg.html#method.is_set
#[derive(Debug, PartialEq, Copy, Clone)] #[derive(Debug, PartialEq, Copy, Clone)]
pub enum ArgSettings { pub enum ArgSettings {
/// Specifies that an arg must be used /// Specifies that an arg must be used

View file

@ -49,8 +49,7 @@ pub enum ValueHint {
/// command line `my_app ls -la /` will be parsed as `["ls", "-la", "/"]` and clap won't try to /// command line `my_app ls -la /` will be parsed as `["ls", "-la", "/"]` and clap won't try to
/// parse the `-la` argument itself. /// parse the `-la` argument itself.
/// ///
/// [`.multiple(true)`]: ./struct.Arg.html#method.multiple /// [`.multiple(true)`]: Arg::multiple()
/// [`AppSettings::TrailingVarArg`]: ./enum.AppSettings.html#variant.TrailingVarArg
CommandWithArguments, CommandWithArguments,
/// Name of a local operating system user. /// Name of a local operating system user.
Username, Username,

View file

@ -70,11 +70,11 @@ use yaml_rust::Yaml;
/// assert!(matches.is_present("vers")); /// assert!(matches.is_present("vers"));
/// // we could also alternatively check each arg individually (not shown here) /// // we could also alternatively check each arg individually (not shown here)
/// ``` /// ```
/// [`ArgGroup::multiple(true)`]: ./struct.ArgGroup.html#method.multiple /// [`ArgGroup::multiple(true)`]: ArgGroup::multiple()
/// [`ArgGroup::multiple(false)`]: ./struct.ArgGroup.html#method.multiple /// [`ArgGroup::multiple(false)`]: ArgGroup::multiple()
/// [arguments]: ./struct.Arg.html /// [arguments]: Arg
/// [conflict]: ./struct.Arg.html#method.conflicts_with /// [conflict]: Arg::conflicts_with()
/// [requirement]: ./struct.Arg.html#method.requires /// [requirement]: Arg::requires()
#[derive(Default, Debug, PartialEq, Eq)] #[derive(Default, Debug, PartialEq, Eq)]
pub struct ArgGroup<'help> { pub struct ArgGroup<'help> {
pub(crate) id: Id, pub(crate) id: Id,
@ -133,7 +133,7 @@ impl<'help> ArgGroup<'help> {
/// // but we can also check individually if needed /// // but we can also check individually if needed
/// assert!(m.is_present("flag")); /// assert!(m.is_present("flag"));
/// ``` /// ```
/// [argument]: ./struct.Arg.html /// [argument]: Arg
pub fn arg<T: Key>(mut self, arg_id: T) -> Self { pub fn arg<T: Key>(mut self, arg_id: T) -> Self {
self.args.push(arg_id.into()); self.args.push(arg_id.into());
self self
@ -158,7 +158,7 @@ impl<'help> ArgGroup<'help> {
/// // but we can also check individually if needed /// // but we can also check individually if needed
/// assert!(m.is_present("flag")); /// assert!(m.is_present("flag"));
/// ``` /// ```
/// [arguments]: ./struct.Arg.html /// [arguments]: Arg
pub fn args<T: Key>(mut self, ns: &[T]) -> Self { pub fn args<T: Key>(mut self, ns: &[T]) -> Self {
for n in ns { for n in ns {
self = self.arg(n); self = self.arg(n);
@ -205,7 +205,6 @@ impl<'help> ArgGroup<'help> {
/// let err = result.unwrap_err(); /// let err = result.unwrap_err();
/// assert_eq!(err.kind, ErrorKind::ArgumentConflict); /// assert_eq!(err.kind, ErrorKind::ArgumentConflict);
/// ``` /// ```
/// [`Arg`]: ./struct.Arg.html
#[inline] #[inline]
pub fn multiple(mut self, m: bool) -> Self { pub fn multiple(mut self, m: bool) -> Self {
self.multiple = m; self.multiple = m;
@ -243,9 +242,8 @@ impl<'help> ArgGroup<'help> {
/// let err = result.unwrap_err(); /// let err = result.unwrap_err();
/// assert_eq!(err.kind, ErrorKind::MissingRequiredArgument); /// assert_eq!(err.kind, ErrorKind::MissingRequiredArgument);
/// ``` /// ```
/// [`App`]: ./struct.App.html
/// [``]: ./struct..html /// [``]: ./struct..html
/// [`ArgGroup::multiple`]: ./struct.ArgGroup.html#method.multiple /// [`ArgGroup::multiple`]: ArgGroup::multiple()
#[inline] #[inline]
pub fn required(mut self, r: bool) -> Self { pub fn required(mut self, r: bool) -> Self {
self.required = r; self.required = r;
@ -280,8 +278,8 @@ impl<'help> ArgGroup<'help> {
/// let err = result.unwrap_err(); /// let err = result.unwrap_err();
/// assert_eq!(err.kind, ErrorKind::MissingRequiredArgument); /// assert_eq!(err.kind, ErrorKind::MissingRequiredArgument);
/// ``` /// ```
/// [required group]: ./struct.ArgGroup.html#method.required /// [required group]: ArgGroup::required()
/// [argument requirement rules]: ./struct.Arg.html#method.requires /// [argument requirement rules]: Arg::requires()
pub fn requires<T: Key>(mut self, id: T) -> Self { pub fn requires<T: Key>(mut self, id: T) -> Self {
self.requires.push(id.into()); self.requires.push(id.into());
self self
@ -317,8 +315,8 @@ impl<'help> ArgGroup<'help> {
/// let err = result.unwrap_err(); /// let err = result.unwrap_err();
/// assert_eq!(err.kind, ErrorKind::MissingRequiredArgument); /// assert_eq!(err.kind, ErrorKind::MissingRequiredArgument);
/// ``` /// ```
/// [required group]: ./struct.ArgGroup.html#method.required /// [required group]: ArgGroup::required()
/// [argument requirement rules]: ./struct.Arg.html#method.requires_all /// [argument requirement rules]: Arg::requires_all()
pub fn requires_all(mut self, ns: &[&'help str]) -> Self { pub fn requires_all(mut self, ns: &[&'help str]) -> Self {
for n in ns { for n in ns {
self = self.requires(n); self = self.requires(n);
@ -352,7 +350,7 @@ impl<'help> ArgGroup<'help> {
/// let err = result.unwrap_err(); /// let err = result.unwrap_err();
/// assert_eq!(err.kind, ErrorKind::ArgumentConflict); /// assert_eq!(err.kind, ErrorKind::ArgumentConflict);
/// ``` /// ```
/// [argument exclusion rules]: ./struct.Arg.html#method.conflicts_with /// [argument exclusion rules]: Arg::conflicts_with()
pub fn conflicts_with<T: Key>(mut self, id: T) -> Self { pub fn conflicts_with<T: Key>(mut self, id: T) -> Self {
self.conflicts.push(id.into()); self.conflicts.push(id.into());
self self
@ -387,7 +385,7 @@ impl<'help> ArgGroup<'help> {
/// let err = result.unwrap_err(); /// let err = result.unwrap_err();
/// assert_eq!(err.kind, ErrorKind::ArgumentConflict); /// assert_eq!(err.kind, ErrorKind::ArgumentConflict);
/// ``` /// ```
/// [argument exclusion rules]: ./struct.Arg.html#method.conflicts_with_all /// [argument exclusion rules]: Arg::conflicts_with_all()
pub fn conflicts_with_all(mut self, ns: &[&'help str]) -> Self { pub fn conflicts_with_all(mut self, ns: &[&'help str]) -> Self {
for n in ns { for n in ns {
self = self.conflicts_with(n); self = self.conflicts_with(n);

View file

@ -66,10 +66,6 @@ use std::ffi::OsString;
/// } /// }
/// ``` /// ```
/// ///
/// [`App`]: ./struct.App.html
/// [`ArgMatches`]: ./struct.ArgMatches.html
/// [`FromArgMatches`]: ./trait.FromArgMatches.html
/// [`IntoApp`]: ./trait.IntoApp.html
pub trait Clap: FromArgMatches + IntoApp + Sized { pub trait Clap: FromArgMatches + IntoApp + Sized {
/// Parse from `std::env::args_os()`, exit on error /// Parse from `std::env::args_os()`, exit on error
fn parse() -> Self { fn parse() -> Self {
@ -146,7 +142,6 @@ pub trait IntoApp: Sized {
/// Converts an instance of [`ArgMatches`] to a consumer defined struct. /// Converts an instance of [`ArgMatches`] to a consumer defined struct.
/// ///
/// [`ArgMatches`]: ./struct.ArgMatches.html
pub trait FromArgMatches: Sized { pub trait FromArgMatches: Sized {
/// It's common to have an "application context" struct (sometimes called /// It's common to have an "application context" struct (sometimes called
/// config) that represents all the normalized values after being processed by /// config) that represents all the normalized values after being processed by

View file

@ -170,7 +170,7 @@ macro_rules! crate_name {
/// ///
/// Equivalent to using the `crate_*!` macros with their respective fields. /// Equivalent to using the `crate_*!` macros with their respective fields.
/// ///
/// Provided separator is for the [`crate_authors!`](macro.crate_authors.html) macro, /// Provided separator is for the [`crate_authors!`] macro,
/// refer to the documentation therefor. /// refer to the documentation therefor.
/// ///
/// **NOTE:** Changing the values in your `Cargo.toml` does not trigger a re-build automatically, /// **NOTE:** Changing the values in your `Cargo.toml` does not trigger a re-build automatically,
@ -285,14 +285,14 @@ macro_rules! app_from_crate {
/// * `(@arg "something-else": --"something-else")` /// * `(@arg "something-else": --"something-else")`
/// * `(@subcommand "something-else" => ...)` /// * `(@subcommand "something-else" => ...)`
/// ///
/// [`Arg::short`]: ./struct.Arg.html#method.short /// [`Arg::short`]: Arg::short()
/// [`Arg::long`]: ./struct.Arg.html#method.long /// [`Arg::long`]: Arg::long()
/// [`Arg::multiple(true)`]: ./struct.Arg.html#method.multiple /// [`Arg::multiple(true)`]: Arg::multiple()
/// [`Arg::value_name`]: ./struct.Arg.html#method.value_name /// [`Arg::value_name`]: Arg::value_name()
/// [`Arg::min_values(min)`]: ./struct.Arg.html#method.min_values /// [`Arg::min_values(min)`]: Arg::min_values()
/// [`Arg::max_values(max)`]: ./struct.Arg.html#method.max_values /// [`Arg::max_values(max)`]: Arg::max_values()
/// [`Arg::validator`]: ./struct.Arg.html#method.validator /// [`Arg::validator`]: Arg::validator()
/// [`Arg::conflicts_with`]: ./struct.Arg.html#method.conflicts_with /// [`Arg::conflicts_with`]: Arg::conflicts_with()
#[macro_export] #[macro_export]
macro_rules! clap_app { macro_rules! clap_app {
(@app ($builder:expr)) => { $builder }; (@app ($builder:expr)) => { $builder };

View file

@ -962,7 +962,7 @@ impl<'help, 'app, 'parser, 'writer> Help<'help, 'app, 'parser, 'writer> {
/// ///
/// For details about the template language see [`App::help_template`]. /// For details about the template language see [`App::help_template`].
/// ///
/// [`App::help_template`]: ./struct.App.html#method.help_template /// [`App::help_template`]: App::help_template()
fn write_templated_help(&mut self, template: &str) -> io::Result<()> { fn write_templated_help(&mut self, template: &str) -> io::Result<()> {
debug!("Help::write_templated_help"); debug!("Help::write_templated_help");

View file

@ -17,7 +17,7 @@ use crate::{
/// Short hand for [`Result`] type /// Short hand for [`Result`] type
/// ///
/// [`Result`]: https://doc.rust-lang.org/std/result/enum.Result.html /// [`Result`]: std::result::Result
pub type Result<T> = StdResult<T, Error>; pub type Result<T> = StdResult<T, Error>;
/// Command line argument parser kind of error /// Command line argument parser kind of error
@ -38,7 +38,6 @@ pub enum ErrorKind {
/// assert!(result.is_err()); /// assert!(result.is_err());
/// assert_eq!(result.unwrap_err().kind, ErrorKind::InvalidValue); /// assert_eq!(result.unwrap_err().kind, ErrorKind::InvalidValue);
/// ``` /// ```
/// [`Arg`]: ./struct.Arg.html
InvalidValue, InvalidValue,
/// Occurs when a user provides a flag, option, argument or subcommand which isn't defined. /// Occurs when a user provides a flag, option, argument or subcommand which isn't defined.
@ -76,7 +75,7 @@ pub enum ErrorKind {
/// assert_eq!(result.unwrap_err().kind, ErrorKind::InvalidSubcommand); /// assert_eq!(result.unwrap_err().kind, ErrorKind::InvalidSubcommand);
/// ``` /// ```
/// [``]: ./struct..html /// [``]: ./struct..html
/// [`UnknownArgument`]: ./enum.ErrorKind.html#variant.UnknownArgument /// [`UnknownArgument`]: ErrorKind::UnknownArgument
InvalidSubcommand, InvalidSubcommand,
/// Occurs when the user provides an unrecognized [``] which either /// Occurs when the user provides an unrecognized [``] which either
@ -102,8 +101,8 @@ pub enum ErrorKind {
/// assert_eq!(result.unwrap_err().kind, ErrorKind::UnrecognizedSubcommand); /// assert_eq!(result.unwrap_err().kind, ErrorKind::UnrecognizedSubcommand);
/// ``` /// ```
/// [``]: ./struct..html /// [``]: ./struct..html
/// [`InvalidSubcommand`]: ./enum.ErrorKind.html#variant.InvalidSubcommand /// [`InvalidSubcommand`]: ErrorKind::InvalidSubcommand
/// [`UnknownArgument`]: ./enum.ErrorKind.html#variant.UnknownArgument /// [`UnknownArgument`]: ErrorKind::UnknownArgument
UnrecognizedSubcommand, UnrecognizedSubcommand,
/// Occurs when the user provides an empty value for an option that does not allow empty /// Occurs when the user provides an empty value for an option that does not allow empty
@ -179,7 +178,7 @@ pub enum ErrorKind {
/// assert!(result.is_err()); /// assert!(result.is_err());
/// assert_eq!(result.unwrap_err().kind, ErrorKind::TooManyValues); /// assert_eq!(result.unwrap_err().kind, ErrorKind::TooManyValues);
/// ``` /// ```
/// [`Arg::max_values`]: ./struct.Arg.html#method.max_values /// [`Arg::max_values`]: Arg::max_values()
TooManyValues, TooManyValues,
/// Occurs when the user provides fewer values for an argument than were defined by setting /// Occurs when the user provides fewer values for an argument than were defined by setting
@ -197,7 +196,7 @@ pub enum ErrorKind {
/// assert!(result.is_err()); /// assert!(result.is_err());
/// assert_eq!(result.unwrap_err().kind, ErrorKind::TooFewValues); /// assert_eq!(result.unwrap_err().kind, ErrorKind::TooFewValues);
/// ``` /// ```
/// [`Arg::min_values`]: ./struct.Arg.html#method.min_values /// [`Arg::min_values`]: Arg::min_values()
TooFewValues, TooFewValues,
/// Occurs when the user provides a different number of values for an argument than what's /// Occurs when the user provides a different number of values for an argument than what's
@ -218,8 +217,8 @@ pub enum ErrorKind {
/// assert_eq!(result.unwrap_err().kind, ErrorKind::WrongNumberOfValues); /// assert_eq!(result.unwrap_err().kind, ErrorKind::WrongNumberOfValues);
/// ``` /// ```
/// ///
/// [`Arg::number_of_values`]: ./struct.Arg.html#method.number_of_values /// [`Arg::number_of_values`]: Arg::number_of_values()
/// [`Arg::value_names`]: ./struct.Arg.html#method.value_names /// [`Arg::value_names`]: Arg::value_names()
WrongNumberOfValues, WrongNumberOfValues,
/// Occurs when the user provides two values which conflict with each other and can't be used /// Occurs when the user provides two values which conflict with each other and can't be used
@ -273,7 +272,6 @@ pub enum ErrorKind {
/// assert_eq!(err.unwrap_err().kind, ErrorKind::MissingSubcommand); /// assert_eq!(err.unwrap_err().kind, ErrorKind::MissingSubcommand);
/// # ; /// # ;
/// ``` /// ```
/// [`AppSettings::SubcommandRequired`]: ./enum.AppSettings.html#variant.SubcommandRequired
MissingSubcommand, MissingSubcommand,
/// Occurs when the user provides multiple values to an argument which doesn't allow that. /// Occurs when the user provides multiple values to an argument which doesn't allow that.
@ -317,7 +315,6 @@ pub enum ErrorKind {
/// assert!(result.is_err()); /// assert!(result.is_err());
/// assert_eq!(result.unwrap_err().kind, ErrorKind::InvalidUtf8); /// assert_eq!(result.unwrap_err().kind, ErrorKind::InvalidUtf8);
/// ``` /// ```
/// [`AppSettings::StrictUtf8`]: ./enum.AppSettings.html#variant.StrictUtf8
InvalidUtf8, InvalidUtf8,
/// Not a true "error" as it means `--help` or similar was used. /// Not a true "error" as it means `--help` or similar was used.
@ -356,9 +353,7 @@ pub enum ErrorKind {
/// assert!(result.is_err()); /// assert!(result.is_err());
/// assert_eq!(result.unwrap_err().kind, ErrorKind::DisplayHelpOnMissingArgumentOrSubcommand); /// assert_eq!(result.unwrap_err().kind, ErrorKind::DisplayHelpOnMissingArgumentOrSubcommand);
/// ``` /// ```
/// [`AppSettings::ArgRequiredElseHelp`]: ./enum.AppSettings.html#variant.ArgRequiredElseHelp /// [`subcommand`]: App::subcommand()
/// [`AppSettings::SubcommandRequiredElseHelp`]: ./enum.AppSettings.html#variant.SubcommandRequiredElseHelp
/// [`subcommand`]: ./struct.App.html#method.subcommand
DisplayHelpOnMissingArgumentOrSubcommand, DisplayHelpOnMissingArgumentOrSubcommand,
/// Not a true "error" as it means `--version` or similar was used. /// Not a true "error" as it means `--version` or similar was used.
@ -379,20 +374,20 @@ pub enum ErrorKind {
/// into type `T`, but the argument you requested wasn't used. I.e. you asked for an argument /// into type `T`, but the argument you requested wasn't used. I.e. you asked for an argument
/// with name `config` to be converted, but `config` wasn't used by the user. /// with name `config` to be converted, but `config` wasn't used by the user.
/// ///
/// [`ArgMatches::value_of_t`]: ./struct.ArgMatches.html#method.value_of_t /// [`ArgMatches::value_of_t`]: ArgMatches::value_of_t()
ArgumentNotFound, ArgumentNotFound,
/// Represents an [I/O error]. /// Represents an [I/O error].
/// Can occur when writing to `stderr` or `stdout` or reading a configuration file. /// Can occur when writing to `stderr` or `stdout` or reading a configuration file.
/// ///
/// [I/O error]: https://doc.rust-lang.org/std/io/struct.Error.html /// [I/O error]: std::io::Error
Io, Io,
/// Represents a [Format error] (which is a part of [`Display`]). /// Represents a [Format error] (which is a part of [`Display`]).
/// Typically caused by writing to `stderr` or `stdout`. /// Typically caused by writing to `stderr` or `stdout`.
/// ///
/// [`Display`]: https://doc.rust-lang.org/std/fmt/trait.Display.html /// [`Display`]: std::fmt::Display
/// [Format error]: https://doc.rust-lang.org/std/fmt/struct.Error.html /// [Format error]: std::fmt::Error
Format, Format,
} }

View file

@ -72,7 +72,7 @@ pub(crate) struct SubCommand {
/// } /// }
/// } /// }
/// ``` /// ```
/// [`App::get_matches`]: ./struct.App.html#method.get_matches /// [`App::get_matches`]: App::get_matches()
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct ArgMatches { pub struct ArgMatches {
pub(crate) args: IndexMap<Id, MatchedArg>, pub(crate) args: IndexMap<Id, MatchedArg>,
@ -115,12 +115,12 @@ impl ArgMatches {
/// ///
/// assert_eq!(m.value_of("output"), Some("something")); /// assert_eq!(m.value_of("output"), Some("something"));
/// ``` /// ```
/// [option]: ./struct.Arg.html#method.takes_value /// [option]: Arg::takes_value()
/// [positional]: ./struct.Arg.html#method.index /// [positional]: Arg::index()
/// [`ArgMatches::values_of`]: ./struct.ArgMatches.html#method.values_of /// [`ArgMatches::values_of`]: ArgMatches::values_of()
/// [`panic!`]: https://doc.rust-lang.org/std/macro.panic!.html /// [`panic!`]: https://doc.rust-lang.org/std/macro.panic!.html
/// [`default_value`]: ./struct.Arg.html#method.default_value /// [`default_value`]: Arg::default_value()
/// [`occurrences_of`]: ./struct.ArgMatches.html#method.occurrences_of /// [`occurrences_of`]: ArgMatches::occurrences_of()
pub fn value_of<T: Key>(&self, id: T) -> Option<&str> { pub fn value_of<T: Key>(&self, id: T) -> Option<&str> {
if let Some(arg) = self.args.get(&Id::from(id)) { if let Some(arg) = self.args.get(&Id::from(id)) {
if let Some(v) = arg.get_val(0) { if let Some(v) = arg.get_val(0) {
@ -155,9 +155,9 @@ impl ArgMatches {
/// OsString::from_vec(vec![b'H', b'i', b' ', 0xe9, b'!'])]); /// OsString::from_vec(vec![b'H', b'i', b' ', 0xe9, b'!'])]);
/// assert_eq!(&*m.value_of_lossy("arg").unwrap(), "Hi \u{FFFD}!"); /// assert_eq!(&*m.value_of_lossy("arg").unwrap(), "Hi \u{FFFD}!");
/// ``` /// ```
/// [`default_value`]: ./struct.Arg.html#method.default_value /// [`default_value`]: Arg::default_value()
/// [`occurrences_of`]: ./struct.ArgMatches.html#method.occurrences_of /// [`occurrences_of`]: ArgMatches::occurrences_of()
/// [`Arg::values_of_lossy`]: ./struct.ArgMatches.html#method.values_of_lossy /// [`Arg::values_of_lossy`]: ArgMatches::values_of_lossy()
pub fn value_of_lossy<T: Key>(&self, id: T) -> Option<Cow<'_, str>> { pub fn value_of_lossy<T: Key>(&self, id: T) -> Option<Cow<'_, str>> {
if let Some(arg) = self.args.get(&Id::from(id)) { if let Some(arg) = self.args.get(&Id::from(id)) {
if let Some(v) = arg.get_val(0) { if let Some(v) = arg.get_val(0) {
@ -195,10 +195,10 @@ impl ArgMatches {
/// OsString::from_vec(vec![b'H', b'i', b' ', 0xe9, b'!'])]); /// OsString::from_vec(vec![b'H', b'i', b' ', 0xe9, b'!'])]);
/// assert_eq!(&*m.value_of_os("arg").unwrap().as_bytes(), [b'H', b'i', b' ', 0xe9, b'!']); /// assert_eq!(&*m.value_of_os("arg").unwrap().as_bytes(), [b'H', b'i', b' ', 0xe9, b'!']);
/// ``` /// ```
/// [`default_value`]: ./struct.Arg.html#method.default_value /// [`default_value`]: Arg::default_value()
/// [`occurrences_of`]: ./struct.ArgMatches.html#method.occurrences_of /// [`occurrences_of`]: ArgMatches::occurrences_of()
/// [`String`]: https://doc.rust-lang.org/std/string/struct.String.html /// [`String`]: std::string::String
/// [`ArgMatches::values_of_os`]: ./struct.ArgMatches.html#method.values_of_os /// [`ArgMatches::values_of_os`]: ArgMatches::values_of_os()
pub fn value_of_os<T: Key>(&self, id: T) -> Option<&OsStr> { pub fn value_of_os<T: Key>(&self, id: T) -> Option<&OsStr> {
self.args self.args
.get(&Id::from(id)) .get(&Id::from(id))
@ -228,8 +228,7 @@ impl ArgMatches {
/// let vals: Vec<&str> = m.values_of("output").unwrap().collect(); /// let vals: Vec<&str> = m.values_of("output").unwrap().collect();
/// assert_eq!(vals, ["val1", "val2", "val3"]); /// assert_eq!(vals, ["val1", "val2", "val3"]);
/// ``` /// ```
/// [`Values`]: ./struct.Values.html /// [`Iterator`]: std::iter::Iterator
/// [`Iterator`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html
pub fn values_of<T: Key>(&self, id: T) -> Option<Values> { pub fn values_of<T: Key>(&self, id: T) -> Option<Values> {
self.args.get(&Id::from(id)).map(|arg| { self.args.get(&Id::from(id)).map(|arg| {
fn to_str_slice(o: &OsString) -> &str { fn to_str_slice(o: &OsString) -> &str {
@ -319,10 +318,9 @@ impl ArgMatches {
/// assert_eq!(itr.next(), Some(OsStr::from_bytes(&[0xe9, b'!']))); /// assert_eq!(itr.next(), Some(OsStr::from_bytes(&[0xe9, b'!'])));
/// assert_eq!(itr.next(), None); /// assert_eq!(itr.next(), None);
/// ``` /// ```
/// [`OsValues`]: ./struct.OsValues.html /// [`Iterator`]: std::iter::Iterator
/// [`Iterator`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html /// [`OsString`]: std::ffi::OsString
/// [`OsString`]: https://doc.rust-lang.org/std/ffi/struct.OsString.html /// [`String`]: std::string::String
/// [`String`]: https://doc.rust-lang.org/std/string/struct.String.html
pub fn values_of_os<T: Key>(&self, id: T) -> Option<OsValues> { pub fn values_of_os<T: Key>(&self, id: T) -> Option<OsValues> {
fn to_str_slice(o: &OsString) -> &OsStr { fn to_str_slice(o: &OsString) -> &OsStr {
o o
@ -366,9 +364,7 @@ impl ArgMatches {
/// let _: u32 = also_len; /// let _: u32 = also_len;
/// ``` /// ```
/// ///
/// [`std::str::FromStr`]: https://doc.rust-lang.org/std/str/trait.FromStr.html /// [`ArgMatches::values_of_t`]: ArgMatches::values_of_t()
/// [`ErrorKind`]: enum.ErrorKind.html
/// [`ArgMatches::values_of_t`]: ./struct.ArgMatches.html#method.values_of_t
/// [`panic!`]: https://doc.rust-lang.org/std/macro.panic!.html /// [`panic!`]: https://doc.rust-lang.org/std/macro.panic!.html
pub fn value_of_t<R>(&self, name: &str) -> Result<R, Error> pub fn value_of_t<R>(&self, name: &str) -> Result<R, Error>
where where
@ -422,7 +418,6 @@ impl ArgMatches {
/// let _: u32 = also_len; /// let _: u32 = also_len;
/// ``` /// ```
/// ///
/// [`std::str::FromStr`]: https://doc.rust-lang.org/std/str/trait.FromStr.html
/// [`panic!`]: https://doc.rust-lang.org/std/macro.panic!.html /// [`panic!`]: https://doc.rust-lang.org/std/macro.panic!.html
pub fn value_of_t_or_exit<R>(&self, name: &str) -> R pub fn value_of_t_or_exit<R>(&self, name: &str) -> R
where where
@ -460,7 +455,6 @@ impl ArgMatches {
/// let _: Vec<u32> = also_len; /// let _: Vec<u32> = also_len;
/// ``` /// ```
/// ///
/// [`std::str::FromStr`]: https://doc.rust-lang.org/std/str/trait.FromStr.html
/// [`panic!`]: https://doc.rust-lang.org/std/macro.panic!.html /// [`panic!`]: https://doc.rust-lang.org/std/macro.panic!.html
pub fn values_of_t<R>(&self, name: &str) -> Result<Vec<R>, Error> pub fn values_of_t<R>(&self, name: &str) -> Result<Vec<R>, Error>
where where
@ -514,7 +508,6 @@ impl ArgMatches {
/// let _: Vec<u32> = also_len; /// let _: Vec<u32> = also_len;
/// ``` /// ```
/// ///
/// [`std::str::FromStr`]: https://doc.rust-lang.org/std/str/trait.FromStr.html
/// [`panic!`]: https://doc.rust-lang.org/std/macro.panic!.html /// [`panic!`]: https://doc.rust-lang.org/std/macro.panic!.html
pub fn values_of_t_or_exit<R>(&self, name: &str) -> Vec<R> pub fn values_of_t_or_exit<R>(&self, name: &str) -> Vec<R>
where where
@ -543,8 +536,8 @@ impl ArgMatches {
/// assert!(m.is_present("debug")); /// assert!(m.is_present("debug"));
/// ``` /// ```
/// ///
/// [`default_value`]: ./struct.Arg.html#method.default_value /// [`default_value`]: Arg::default_value()
/// [`occurrences_of`]: ./struct.ArgMatches.html#method.occurrences_of /// [`occurrences_of`]: ArgMatches::occurrences_of()
pub fn is_present<T: Key>(&self, id: T) -> bool { pub fn is_present<T: Key>(&self, id: T) -> bool {
let id = Id::from(id); let id = Id::from(id);
@ -729,8 +722,7 @@ impl ArgMatches {
/// assert_eq!(m.index_of("option"), Some(2)); /// assert_eq!(m.index_of("option"), Some(2));
/// assert_eq!(m.indices_of("option").unwrap().collect::<Vec<_>>(), &[2, 3, 4]); /// assert_eq!(m.indices_of("option").unwrap().collect::<Vec<_>>(), &[2, 3, 4]);
/// ``` /// ```
/// [`ArgMatches`]: ./struct.ArgMatches.html /// [delimiter]: Arg::value_delimiter()
/// [delimiter]: ./struct.Arg.html#method.value_delimiter
pub fn index_of<T: Key>(&self, name: T) -> Option<usize> { pub fn index_of<T: Key>(&self, name: T) -> Option<usize> {
if let Some(arg) = self.args.get(&Id::from(name)) { if let Some(arg) = self.args.get(&Id::from(name)) {
if let Some(i) = arg.get_index(0) { if let Some(i) = arg.get_index(0) {
@ -810,9 +802,8 @@ impl ArgMatches {
/// // ^0 ^1 ^2 /// // ^0 ^1 ^2
/// assert_eq!(m.indices_of("option").unwrap().collect::<Vec<_>>(), &[2]); /// assert_eq!(m.indices_of("option").unwrap().collect::<Vec<_>>(), &[2]);
/// ``` /// ```
/// [`ArgMatches`]: ./struct.ArgMatches.html /// [`ArgMatches::index_of`]: ArgMatches::index_of()
/// [`ArgMatches::index_of`]: ./struct.ArgMatches.html#method.index_of /// [delimiter]: Arg::value_delimiter()
/// [delimiter]: ./struct.Arg.html#method.value_delimiter
pub fn indices_of<T: Key>(&self, id: T) -> Option<Indices<'_>> { pub fn indices_of<T: Key>(&self, id: T) -> Option<Indices<'_>> {
self.args.get(&Id::from(id)).map(|arg| Indices { self.args.get(&Id::from(id)).map(|arg| Indices {
iter: arg.indices(), iter: arg.indices(),
@ -848,8 +839,6 @@ impl ArgMatches {
/// } /// }
/// ``` /// ```
/// [`Subcommand`]: ./struct..html /// [`Subcommand`]: ./struct..html
/// [`App`]: ./struct.App.html
/// [`ArgMatches`]: ./struct.ArgMatches.html
pub fn subcommand_matches<T: Key>(&self, id: T) -> Option<&ArgMatches> { pub fn subcommand_matches<T: Key>(&self, id: T) -> Option<&ArgMatches> {
if let Some(ref s) = self.subcommand { if let Some(ref s) = self.subcommand {
if s.id == id.into() { if s.id == id.into() {
@ -915,8 +904,6 @@ impl ArgMatches {
/// } /// }
/// ``` /// ```
/// [`Subcommand`]: ./struct..html /// [`Subcommand`]: ./struct..html
/// [`App`]: ./struct.App.html
/// [`ArgMatches`]: ./struct.ArgMatches.html
#[inline] #[inline]
pub fn subcommand_name(&self) -> Option<&str> { pub fn subcommand_name(&self) -> Option<&str> {
self.subcommand.as_ref().map(|sc| &*sc.name) self.subcommand.as_ref().map(|sc| &*sc.name)
@ -967,8 +954,8 @@ impl ArgMatches {
/// _ => {}, /// _ => {},
/// } /// }
/// ``` /// ```
/// [`ArgMatches::subcommand_matches`]: ./struct.ArgMatches.html#method.subcommand_matches /// [`ArgMatches::subcommand_matches`]: ArgMatches::subcommand_matches()
/// [`ArgMatches::subcommand_name`]: ./struct.ArgMatches.html#method.subcommand_name /// [`ArgMatches::subcommand_name`]: ArgMatches::subcommand_name()
#[inline] #[inline]
pub fn subcommand(&self) -> Option<(&str, &ArgMatches)> { pub fn subcommand(&self) -> Option<(&str, &ArgMatches)> {
self.subcommand.as_ref().map(|sc| (&*sc.name, &sc.matches)) self.subcommand.as_ref().map(|sc| (&*sc.name, &sc.matches))
@ -1000,7 +987,7 @@ impl ArgMatches {
/// assert_eq!(values.next(), Some("val2")); /// assert_eq!(values.next(), Some("val2"));
/// assert_eq!(values.next(), None); /// assert_eq!(values.next(), None);
/// ``` /// ```
/// [`ArgMatches::values_of`]: ./struct.ArgMatches.html#method.values_of /// [`ArgMatches::values_of`]: ArgMatches::values_of()
#[derive(Clone)] #[derive(Clone)]
#[allow(missing_debug_implementations)] #[allow(missing_debug_implementations)]
pub struct Values<'a> { pub struct Values<'a> {
@ -1092,8 +1079,7 @@ impl<'a> Default for GroupedValues<'a> {
/// OsString::from_vec(vec![b'H', b'i', b' ', 0xe9, b'!'])]); /// OsString::from_vec(vec![b'H', b'i', b' ', 0xe9, b'!'])]);
/// assert_eq!(&*m.value_of_os("arg").unwrap().as_bytes(), [b'H', b'i', b' ', 0xe9, b'!']); /// assert_eq!(&*m.value_of_os("arg").unwrap().as_bytes(), [b'H', b'i', b' ', 0xe9, b'!']);
/// ``` /// ```
/// [`ArgMatches::values_of_os`]: ./struct.ArgMatches.html#method.values_of_os /// [`ArgMatches::values_of_os`]: ArgMatches::values_of_os()
/// [`Values`]: ./struct.Values.html
#[derive(Clone)] #[derive(Clone)]
#[allow(missing_debug_implementations)] #[allow(missing_debug_implementations)]
pub struct OsValues<'a> { pub struct OsValues<'a> {
@ -1150,7 +1136,7 @@ impl Default for OsValues<'_> {
/// assert_eq!(indices.next(), Some(3)); /// assert_eq!(indices.next(), Some(3));
/// assert_eq!(indices.next(), None); /// assert_eq!(indices.next(), None);
/// ``` /// ```
/// [`ArgMatches::indices_of`]: ./struct.ArgMatches.html#method.indices_of /// [`ArgMatches::indices_of`]: ArgMatches::indices_of()
#[derive(Clone)] #[derive(Clone)]
#[allow(missing_debug_implementations)] #[allow(missing_debug_implementations)]
pub struct Indices<'a> { pub struct Indices<'a> {