2015-09-30 21:14:48 +00:00
|
|
|
#[allow(dead_code)]
|
2015-08-30 21:10:26 +00:00
|
|
|
mod settings;
|
2015-11-09 13:57:20 +00:00
|
|
|
#[macro_use]
|
|
|
|
mod macros;
|
2016-01-11 08:59:56 +00:00
|
|
|
mod parser;
|
|
|
|
mod meta;
|
2016-04-01 06:00:11 +00:00
|
|
|
mod help;
|
2015-08-30 21:10:26 +00:00
|
|
|
|
|
|
|
pub use self::settings::AppSettings;
|
2015-11-09 08:48:49 +00:00
|
|
|
|
|
|
|
use std::env;
|
|
|
|
use std::io::{self, BufRead, BufWriter, Write};
|
|
|
|
use std::path::Path;
|
|
|
|
use std::process;
|
2016-01-11 08:59:56 +00:00
|
|
|
use std::ffi::OsString;
|
2015-11-09 08:48:49 +00:00
|
|
|
use std::borrow::Borrow;
|
2016-03-16 14:17:00 +00:00
|
|
|
use std::result::Result as StdResult;
|
|
|
|
use std::rc::Rc;
|
|
|
|
use std::fmt;
|
2015-11-09 08:48:49 +00:00
|
|
|
|
|
|
|
#[cfg(feature = "yaml")]
|
|
|
|
use yaml_rust::Yaml;
|
2016-03-16 14:17:00 +00:00
|
|
|
use vec_map::VecMap;
|
2015-11-09 08:48:49 +00:00
|
|
|
|
2016-05-06 21:35:53 +00:00
|
|
|
use args::{AnyArg, Arg, ArgGroup, ArgMatcher, ArgMatches, ArgSettings};
|
2016-01-11 08:59:56 +00:00
|
|
|
use app::parser::Parser;
|
2016-04-01 06:00:11 +00:00
|
|
|
use app::help::Help;
|
2016-01-11 08:59:56 +00:00
|
|
|
use errors::Error;
|
|
|
|
use errors::Result as ClapResult;
|
2015-11-09 08:48:49 +00:00
|
|
|
|
|
|
|
/// Used to create a representation of a command line program and all possible command line
|
2016-01-26 19:02:10 +00:00
|
|
|
/// arguments. Application settings are set using the "builder pattern" with the
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`App::get_matches`] family of methods being the terminal methods that starts the
|
|
|
|
/// runtime-parsing process. These methods then return information about the user supplied
|
|
|
|
/// arguments (or lack there of).
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// **NOTE:** There aren't any mandatory "options" that one must set. The "options" may
|
2016-05-14 20:25:00 +00:00
|
|
|
/// also appear in any order (so long as one of the [`App::get_matches`] methods is the last method
|
2016-01-26 19:02:10 +00:00
|
|
|
/// called).
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg};
|
2016-01-26 19:02:10 +00:00
|
|
|
/// let m = App::new("My Program")
|
|
|
|
/// .author("Me, me@mail.com")
|
|
|
|
/// .version("1.0.2")
|
|
|
|
/// .about("Explains in brief what the program does")
|
|
|
|
/// .arg(
|
|
|
|
/// Arg::with_name("in_file").index(1)
|
|
|
|
/// )
|
|
|
|
/// .after_help("Longer explaination to appear after the options when \
|
|
|
|
/// displaying the help information from --help or -h")
|
|
|
|
/// .get_matches();
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// // Your program logic starts here...
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`App::get_matches`]: ./struct.App.html#method.get_matches
|
2015-11-09 08:48:49 +00:00
|
|
|
#[allow(missing_debug_implementations)]
|
2016-05-06 21:35:53 +00:00
|
|
|
pub struct App<'a, 'b>
|
|
|
|
where 'a: 'b
|
|
|
|
{
|
2016-02-04 16:54:46 +00:00
|
|
|
#[doc(hidden)]
|
2016-05-06 21:35:53 +00:00
|
|
|
pub p: Parser<'a, 'b>,
|
2016-02-04 16:54:46 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 08:48:49 +00:00
|
|
|
|
2016-01-11 08:59:56 +00:00
|
|
|
impl<'a, 'b> App<'a, 'b> {
|
2016-01-26 19:02:10 +00:00
|
|
|
/// Creates a new instance of an application requiring a name. The name may be, but doesn't
|
|
|
|
/// have to be same as the binary. The name will be displayed to the user when they request to
|
|
|
|
/// print version or help and usage information.
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg};
|
2016-01-26 19:02:10 +00:00
|
|
|
/// let prog = App::new("My Program")
|
|
|
|
/// # ;
|
2015-11-09 08:48:49 +00:00
|
|
|
/// ```
|
2016-05-06 21:35:53 +00:00
|
|
|
pub fn new<S: Into<String>>(n: S) -> Self {
|
|
|
|
App { p: Parser::with_name(n.into()) }
|
|
|
|
}
|
2015-11-09 08:48:49 +00:00
|
|
|
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Creates a new instace of [`App`] from a .yml (YAML) file. A full example of supported YAML
|
|
|
|
/// objects can be found in [`examples/17_yaml.rs`] and [`examples/17_yaml.yml`]. One great use
|
|
|
|
/// for using YAML is when supporting multiple languages and dialects, as each language could
|
|
|
|
/// be a distinct YAML file and determined at compiletime via `cargo` "features" in your
|
2016-01-26 19:02:10 +00:00
|
|
|
/// `Cargo.toml`
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// In order to use this function you must compile `clap` with the `features = ["yaml"]` in
|
|
|
|
/// your settings for the `[dependencies.clap]` table of your `Cargo.toml`
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// **NOTE:** Due to how the YAML objects are built there is a convienience macro for loading
|
|
|
|
/// the YAML file at compile time (relative to the current file, like modules work). That YAML
|
|
|
|
/// object can then be passed to this function.
|
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
2016-05-14 20:25:00 +00:00
|
|
|
/// The YAML file must be properly formatted or this function will [`panic!`]. A good way to
|
2016-01-26 19:02:10 +00:00
|
|
|
/// ensure this doesn't happen is to run your program with the `--help` switch. If this passes
|
|
|
|
/// without error, you needn't worry because the YAML is properly formatted.
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// The following example shows how to load a properly formatted YAML file to build an instnace
|
2016-05-14 20:25:00 +00:00
|
|
|
/// of an [`App`] struct.
|
2016-01-26 19:02:10 +00:00
|
|
|
///
|
2015-11-09 08:48:49 +00:00
|
|
|
/// ```ignore
|
|
|
|
/// # use clap::App;
|
|
|
|
/// let yml = load_yaml!("app.yml");
|
|
|
|
/// let app = App::from_yaml(yml);
|
2016-01-26 19:02:10 +00:00
|
|
|
///
|
|
|
|
/// // continued logic goes here, such as `app.get_matches()` etc.
|
2015-11-09 08:48:49 +00:00
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`App`]: ./struct.App.html
|
|
|
|
/// [`examples/17_yaml.rs`]: https://github.com/kbknapp/clap-rs/blob/master/examples/17_yaml.rs
|
|
|
|
/// [`examples/17_yaml.yml`]: https://github.com/kbknapp/clap-rs/blob/master/examples/17_yaml.yml
|
|
|
|
/// [`panic!`]: https://doc.rust-lang.org/std/macro.panic!.html
|
2015-11-09 08:48:49 +00:00
|
|
|
#[cfg(feature = "yaml")]
|
2016-02-04 06:10:37 +00:00
|
|
|
pub fn from_yaml(yaml: &'a Yaml) -> App<'a, 'a> {
|
|
|
|
App::from(yaml)
|
2015-11-09 08:48:49 +00:00
|
|
|
}
|
|
|
|
|
2016-05-06 21:35:53 +00:00
|
|
|
/// Sets a string of author(s) that will be displayed to the user when they
|
2016-04-11 23:17:44 +00:00
|
|
|
/// request the help information with `--help` or `-h`.
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
2016-05-06 21:35:53 +00:00
|
|
|
/// **Pro-tip:** If you turn on unstable features you can use `clap`s
|
2016-05-14 20:25:00 +00:00
|
|
|
/// convienience macro [`crate_authors!`] to automatically set your
|
2016-05-06 21:35:53 +00:00
|
|
|
/// application's author to the same thing as your crate at compile time.
|
2016-05-14 20:25:00 +00:00
|
|
|
/// See the [`examples/`]
|
2016-04-11 23:17:44 +00:00
|
|
|
/// directory for more information
|
2016-05-06 21:35:53 +00:00
|
|
|
///
|
2015-11-09 08:48:49 +00:00
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .author("Me, me@mymain.com")
|
|
|
|
/// # ;
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`crate_authors!`]: ./macro.crate_authors!.html
|
|
|
|
/// [`examples/`]: https://github.com/kbknapp/clap-rs/tree/master/examples
|
2016-01-11 08:59:56 +00:00
|
|
|
pub fn author<S: Into<&'b str>>(mut self, author: S) -> Self {
|
2016-02-04 16:54:46 +00:00
|
|
|
self.p.meta.author = Some(author.into());
|
2015-11-09 08:48:49 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Overrides the system-determined binary name. This should only be used when absolutely
|
2016-01-26 19:02:10 +00:00
|
|
|
/// neccessary, such as when the binary name for your application is misleading, or perhaps
|
|
|
|
/// *not* how the user should invoke your program.
|
|
|
|
///
|
|
|
|
/// **Pro-tip:** When building things such as third party `cargo` subcommands, this setting
|
|
|
|
/// **should** be used!
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
2016-05-14 20:25:00 +00:00
|
|
|
/// **NOTE:** This command **should not** be used for [`SubCommand`]s.
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg};
|
2016-01-26 19:02:10 +00:00
|
|
|
/// App::new("My Program")
|
2015-11-09 08:48:49 +00:00
|
|
|
/// .bin_name("my_binary")
|
|
|
|
/// # ;
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`SubCommand`]: ./struct.SubCommand.html
|
2016-01-11 08:59:56 +00:00
|
|
|
pub fn bin_name<S: Into<String>>(mut self, name: S) -> Self {
|
2016-02-04 16:54:46 +00:00
|
|
|
self.p.meta.bin_name = Some(name.into());
|
2015-11-09 08:48:49 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2016-01-26 19:02:10 +00:00
|
|
|
/// Sets a string describing what the program does. This will be displayed when displaying help
|
|
|
|
/// information.
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .about("Does really amazing things to great people")
|
|
|
|
/// # ;
|
|
|
|
/// ```
|
2016-01-11 08:59:56 +00:00
|
|
|
pub fn about<S: Into<&'b str>>(mut self, about: S) -> Self {
|
2016-02-04 16:54:46 +00:00
|
|
|
self.p.meta.about = Some(about.into());
|
2015-11-09 08:48:49 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2016-01-26 19:02:10 +00:00
|
|
|
/// Adds additional help information to be displayed in addition to auto-generated help. This
|
|
|
|
/// information is displayed **after** the auto-generated help information. This is often used
|
|
|
|
/// to describe how to use the arguments, or caveats to be noted.
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::App;
|
|
|
|
/// App::new("myprog")
|
2016-01-26 19:02:10 +00:00
|
|
|
/// .after_help("Does really amazing things to great people...but be careful with -R")
|
2015-11-09 08:48:49 +00:00
|
|
|
/// # ;
|
|
|
|
/// ```
|
2016-01-11 08:59:56 +00:00
|
|
|
pub fn after_help<S: Into<&'b str>>(mut self, help: S) -> Self {
|
2016-02-04 16:54:46 +00:00
|
|
|
self.p.meta.more_help = Some(help.into());
|
2015-11-09 08:48:49 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2016-05-02 18:25:05 +00:00
|
|
|
/// Adds additional help information to be displayed in addition to auto-generated help. This
|
|
|
|
/// information is displayed **before** the auto-generated help information. This is often used
|
|
|
|
/// for header information.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::App;
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .before_help("Some info I'd like to appear before the help info")
|
|
|
|
/// # ;
|
|
|
|
/// ```
|
|
|
|
pub fn before_help<S: Into<&'b str>>(mut self, help: S) -> Self {
|
|
|
|
self.p.meta.pre_help = Some(help.into());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2015-11-09 08:48:49 +00:00
|
|
|
/// Sets a string of the version number to be displayed when displaying version or help
|
|
|
|
/// information.
|
|
|
|
///
|
2016-05-14 20:25:00 +00:00
|
|
|
/// **Pro-tip:** Use `clap`s convienience macro [`crate_version!`] to automatically set your
|
|
|
|
/// application's version to the same thing as your crate at compile time. See the [`examples/`]
|
2016-01-26 19:02:10 +00:00
|
|
|
/// directory for more information
|
|
|
|
///
|
2015-11-09 08:48:49 +00:00
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .version("v0.1.24")
|
|
|
|
/// # ;
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`crate_authors!`]: ./macro.crate_authors!.html
|
|
|
|
/// [`examples/`]: https://github.com/kbknapp/clap-rs/tree/master/examples
|
2016-01-11 08:59:56 +00:00
|
|
|
pub fn version<S: Into<&'b str>>(mut self, ver: S) -> Self {
|
2016-02-04 16:54:46 +00:00
|
|
|
self.p.meta.version = Some(ver.into());
|
2015-11-09 08:48:49 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Sets a custom usage string to override the auto-generated usage string.
|
|
|
|
///
|
|
|
|
/// This will be displayed to the user when errors are found in argument parsing, or when you
|
2016-05-14 20:25:00 +00:00
|
|
|
/// call [`ArgMatches::usage`]
|
2016-01-26 19:02:10 +00:00
|
|
|
///
|
|
|
|
/// **CAUTION:** Using this setting disables `clap`s "context-aware" usage strings. After this
|
|
|
|
/// setting is set, this will be the only usage string displayed to the user!
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// **NOTE:** You do not need to specify the "USAGE: \n\t" portion, as that will
|
|
|
|
/// still be applied by `clap`, you only need to specify the portion starting
|
|
|
|
/// with the binary name.
|
|
|
|
///
|
|
|
|
/// **NOTE:** This will not replace the entire help message, *only* the portion
|
|
|
|
/// showing the usage.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .usage("myapp [-clDas] <some_file>")
|
|
|
|
/// # ;
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`ArgMatches::usage`]: ./struct.ArgMatches.html#method.usage
|
2016-01-11 08:59:56 +00:00
|
|
|
pub fn usage<S: Into<&'b str>>(mut self, usage: S) -> Self {
|
2016-02-04 16:54:46 +00:00
|
|
|
self.p.meta.usage_str = Some(usage.into());
|
2015-11-09 08:48:49 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Sets a custom help message and overrides the auto-generated one. This should only be used
|
|
|
|
/// when the auto-generated message does not suffice.
|
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// This will be displayed to the user when they use `--help` or `-h`
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// **NOTE:** This replaces the **entire** help message, so nothing will be auto-generated.
|
|
|
|
///
|
|
|
|
/// **NOTE:** This **only** replaces the help message for the current command, meaning if you
|
|
|
|
/// are using subcommands, those help messages will still be auto-generated unless you
|
2016-05-14 20:25:00 +00:00
|
|
|
/// specify a [`Arg::help`] for them as well.
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg};
|
|
|
|
/// App::new("myapp")
|
|
|
|
/// .help("myapp v1.0\n\
|
|
|
|
/// Does awesome things\n\
|
|
|
|
/// (C) me@mail.com\n\n\
|
|
|
|
///
|
|
|
|
/// USAGE: myapp <opts> <comamnd>\n\n\
|
|
|
|
///
|
|
|
|
/// Options:\n\
|
|
|
|
/// -h, --helpe Dispay this message\n\
|
|
|
|
/// -V, --version Display version info\n\
|
|
|
|
/// -s <stuff> Do something with stuff\n\
|
|
|
|
/// -v Be verbose\n\n\
|
|
|
|
///
|
|
|
|
/// Commmands:\n\
|
|
|
|
/// help Prints this message\n\
|
|
|
|
/// work Do some work")
|
|
|
|
/// # ;
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`Arg::help`]: ./struct.Arg.html#method.help
|
2016-01-11 08:59:56 +00:00
|
|
|
pub fn help<S: Into<&'b str>>(mut self, help: S) -> Self {
|
2016-02-04 16:54:46 +00:00
|
|
|
self.p.meta.help_str = Some(help.into());
|
2015-11-09 08:48:49 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Sets the [`short`] for the auto-generated `help` argument.
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
2016-05-14 20:25:00 +00:00
|
|
|
/// By default `clap` automatically assigns `h`, but this can be overridden if you have a
|
|
|
|
/// different argument which you'd prefer to use the `-h` short with. This can be done by
|
|
|
|
/// defining your own argument with a lowercase `h` as the [`short`].
|
|
|
|
///
|
|
|
|
/// `clap` lazily generates these `help` arguments **after** you've defined any arguments of
|
|
|
|
/// your own.
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// **NOTE:** Any leading `-` characters will be stripped, and only the first
|
2016-05-14 20:25:00 +00:00
|
|
|
/// non `-` chacter will be used as the [`short`] version
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg};
|
|
|
|
/// App::new("myprog")
|
2016-01-26 19:02:10 +00:00
|
|
|
/// .help_short("H") // Using an uppercase `H` instead of the default lowercase `h`
|
2015-11-09 08:48:49 +00:00
|
|
|
/// # ;
|
2016-01-26 19:02:10 +00:00
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`short`]: ./struct.Arg.html#method.short
|
2016-01-11 08:59:56 +00:00
|
|
|
pub fn help_short<S: AsRef<str> + 'b>(mut self, s: S) -> Self {
|
2016-02-04 16:54:46 +00:00
|
|
|
self.p.help_short(s.as_ref());
|
2015-11-09 08:48:49 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Sets the [`short`] for the auto-generated `version` argument.
|
|
|
|
///
|
|
|
|
/// By default `clap` automatically assigns `V`, but this can be overridden if you have a
|
|
|
|
/// different argument which you'd prefer to use the `-V` short with. This can be done by
|
|
|
|
/// defining your own argument with an uppercase `V` as the [`short`].
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
2016-05-14 20:25:00 +00:00
|
|
|
/// `clap` lazily generates these `version` arguments **after** you've defined any arguments of
|
|
|
|
/// your own.
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// **NOTE:** Any leading `-` characters will be stripped, and only the first
|
|
|
|
/// non `-` chacter will be used as the `short` version
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg};
|
|
|
|
/// App::new("myprog")
|
2016-01-26 19:02:10 +00:00
|
|
|
/// .version_short("v") // Using a lowercase `v` instead of the default capital `V`
|
2015-11-09 08:48:49 +00:00
|
|
|
/// # ;
|
2016-01-26 19:02:10 +00:00
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`short`]: ./struct.Arg.html#method.short
|
2016-01-11 08:59:56 +00:00
|
|
|
pub fn version_short<S: AsRef<str>>(mut self, s: S) -> Self {
|
2016-02-04 16:54:46 +00:00
|
|
|
self.p.version_short(s.as_ref());
|
2015-11-09 08:48:49 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2016-04-03 04:20:55 +00:00
|
|
|
/// Sets the help template to be used, overriding the default format.
|
|
|
|
///
|
|
|
|
/// Tags arg given inside curly brackets:
|
|
|
|
/// Valid tags are:
|
|
|
|
/// * `{bin}` - Binary name.
|
|
|
|
/// * `{version}` - Version number.
|
|
|
|
/// * `{author}` - Author information.
|
|
|
|
/// * `{usage}` - Automatically generated or given usage string.
|
|
|
|
/// * `{all-args}` - Help for all arguments (options, flags, positionals arguments,
|
|
|
|
/// and subcommands) including titles.
|
|
|
|
/// * `{unified}` - Unified help for options and flags.
|
|
|
|
/// * `{flags}` - Help for flags.
|
|
|
|
/// * `{options}` - Help for options.
|
|
|
|
/// * `{positionals}` - Help for positionals arguments.
|
|
|
|
/// * `{subcommands}` - Help for subcommands.
|
|
|
|
/// * `{after-help}` - Help for flags.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .version("1.0")
|
|
|
|
/// .template("{bin} ({version}) - {usage}")
|
|
|
|
/// # ;
|
|
|
|
/// ```
|
|
|
|
/// **NOTE:**The template system is, on purpose, very simple. Therefore the tags have to writen
|
|
|
|
/// in the lowercase and without spacing.
|
|
|
|
pub fn template<S: Into<&'b str>>(mut self, s: S) -> Self {
|
|
|
|
self.p.meta.template = Some(s.into());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Enables a single command, or [`SubCommand`], level settings.
|
2016-01-26 19:02:10 +00:00
|
|
|
///
|
2016-05-14 20:25:00 +00:00
|
|
|
/// See [`AppSettings`] for a full list of possibilities and examples.
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg, AppSettings};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .setting(AppSettings::SubcommandRequired)
|
|
|
|
/// .setting(AppSettings::WaitOnError)
|
|
|
|
/// # ;
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`SubCommand`]: ./struct.SubCommand.html
|
|
|
|
/// [`AppSettings`]: ./enum.AppSettings.html
|
2015-11-09 08:48:49 +00:00
|
|
|
pub fn setting(mut self, setting: AppSettings) -> Self {
|
2016-02-04 16:54:46 +00:00
|
|
|
self.p.set(setting);
|
2015-11-09 08:48:49 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Enables multiple command, or [`SubCommand`], level settings
|
2016-01-26 19:02:10 +00:00
|
|
|
///
|
2016-05-14 20:25:00 +00:00
|
|
|
/// See [`AppSettings`] for a full list of possibilities and examples.
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg, AppSettings};
|
|
|
|
/// App::new("myprog")
|
2016-01-26 19:02:10 +00:00
|
|
|
/// .settings(&[AppSettings::SubcommandRequired,
|
2015-11-09 08:48:49 +00:00
|
|
|
/// AppSettings::WaitOnError])
|
|
|
|
/// # ;
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`SubCommand`]: ./struct.SubCommand.html
|
|
|
|
/// [`AppSettings`]: ./enum.AppSettings.html
|
2015-11-09 08:48:49 +00:00
|
|
|
pub fn settings(mut self, settings: &[AppSettings]) -> Self {
|
|
|
|
for s in settings {
|
2016-02-04 16:54:46 +00:00
|
|
|
self.p.set(*s);
|
2015-11-09 08:48:49 +00:00
|
|
|
}
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Adds an [argument] to the list of valid possibilties.
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// // Adding a single "flag" argument with a short and help text, using Arg::with_name()
|
|
|
|
/// .arg(
|
|
|
|
/// Arg::with_name("debug")
|
|
|
|
/// .short("d")
|
|
|
|
/// .help("turns on debugging mode")
|
|
|
|
/// )
|
|
|
|
/// // Adding a single "option" argument with a short, a long, and help text using the less
|
|
|
|
/// // verbose Arg::from_usage()
|
|
|
|
/// .arg(
|
|
|
|
/// Arg::from_usage("-c --config=[CONFIG] 'Optionally sets a config file to use'")
|
|
|
|
/// )
|
|
|
|
/// # ;
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [argument]: ./struct.Arg.html
|
2016-01-11 08:59:56 +00:00
|
|
|
pub fn arg<A: Borrow<Arg<'a, 'b>> + 'a>(mut self, a: A) -> Self {
|
2016-02-04 16:54:46 +00:00
|
|
|
self.p.add_arg(a.borrow());
|
2015-11-09 08:48:49 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Adds multiple [arguments] to the list of valid possibilties
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .args(
|
2016-01-26 19:02:10 +00:00
|
|
|
/// &[Arg::from_usage("[debug] -d 'turns on debugging info'"),
|
2016-01-22 04:18:52 +00:00
|
|
|
/// Arg::with_name("input").index(1).help("the input file to use")]
|
2015-11-09 08:48:49 +00:00
|
|
|
/// )
|
|
|
|
/// # ;
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [arguments]: ./struct.Arg.html
|
2016-01-11 08:59:56 +00:00
|
|
|
pub fn args(mut self, args: &[Arg<'a, 'b>]) -> Self {
|
|
|
|
for arg in args {
|
2016-02-04 16:54:46 +00:00
|
|
|
self.p.add_arg(arg);
|
2015-11-09 08:48:49 +00:00
|
|
|
}
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2016-05-14 20:25:00 +00:00
|
|
|
/// A convienience method for adding a single [argument] from a usage type string. The string
|
|
|
|
/// used follows the same rules and syntax as [`Arg::from_usage`]
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// **NOTE:** The downside to using this method is that you can not set any additional
|
2016-05-14 20:25:00 +00:00
|
|
|
/// properties of the [`Arg`] other than what [`Arg::from_usage`] supports.
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg};
|
|
|
|
/// App::new("myprog")
|
2016-01-26 19:02:10 +00:00
|
|
|
/// .arg_from_usage("-c --config=<FILE> 'Sets a configuration file to use'")
|
2015-11-09 08:48:49 +00:00
|
|
|
/// # ;
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [arguments]: ./struct.Arg.html
|
|
|
|
/// [`Arg`]: ./struct.Arg.html
|
|
|
|
/// [`Arg::from_usage`]: ./struct.Arg.html#method.from_usage
|
2016-01-11 08:59:56 +00:00
|
|
|
pub fn arg_from_usage(mut self, usage: &'a str) -> Self {
|
2016-02-04 16:54:46 +00:00
|
|
|
self.p.add_arg(&Arg::from_usage(usage));
|
2015-11-09 08:48:49 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Adds multiple [arguments] at once from a usage string, one per line. See
|
|
|
|
/// [`Arg::from_usage`] for details on the syntax and rules supported.
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
2016-05-14 20:25:00 +00:00
|
|
|
/// **NOTE:** Like [`App::arg_from_usage`] the downside is you only set properties for the
|
|
|
|
/// [`Arg`]s which [`Arg::from_usage`] supports.
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .args_from_usage(
|
2016-01-26 19:02:10 +00:00
|
|
|
/// "-c --config=[FILE] 'Sets a configuration file to use'
|
2015-11-09 08:48:49 +00:00
|
|
|
/// [debug]... -d 'Sets the debugging level'
|
2016-01-26 19:02:10 +00:00
|
|
|
/// <FILE> 'The input file to use'"
|
2015-11-09 08:48:49 +00:00
|
|
|
/// )
|
|
|
|
/// # ;
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [arguments]: ./struct.Arg.html
|
|
|
|
/// [`Arg::from_usage`]: ./struct.Arg.html#method.from_usage
|
|
|
|
/// [`App::arg_from_usage`]: ./struct.App.html#method.arg_from_usage
|
|
|
|
/// [`Arg`]: ./struct.Arg.html
|
2016-01-11 08:59:56 +00:00
|
|
|
pub fn args_from_usage(mut self, usage: &'a str) -> Self {
|
2016-03-10 21:36:23 +00:00
|
|
|
for line in usage.lines() {
|
|
|
|
let l = line.trim();
|
2016-05-06 21:35:53 +00:00
|
|
|
if l.is_empty() {
|
|
|
|
continue;
|
|
|
|
}
|
2016-03-10 21:36:23 +00:00
|
|
|
self.p.add_arg(&Arg::from_usage(l));
|
2015-11-09 08:48:49 +00:00
|
|
|
}
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Allows adding a [`SubCommand`] alias, which function as "hidden" subcommands that
|
|
|
|
/// automatically dispatch as if this subcommand was used. This is more efficient, and easier
|
|
|
|
/// than creating multiple hidden subcommands as one only needs to check for the existing of
|
|
|
|
/// this command, and not all vairants.
|
2016-05-10 19:21:19 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg, SubCommand};
|
|
|
|
/// let m = App::new("myprog")
|
|
|
|
/// .subcommand(SubCommand::with_name("test")
|
|
|
|
/// .alias("do-stuff"))
|
|
|
|
/// .get_matches_from(vec!["myprog", "do-stuff"]);
|
|
|
|
/// assert_eq!(m.subcommand_name(), Some("test"));
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`SubCommand`]: ./struct.SubCommand.html
|
2016-05-10 19:21:19 +00:00
|
|
|
pub fn alias<S: Into<&'b str>>(mut self, name: S) -> Self {
|
|
|
|
if let Some(ref mut als) = self.p.meta.aliases {
|
|
|
|
als.push(name.into());
|
|
|
|
} else {
|
|
|
|
self.p.meta.aliases = Some(vec![name.into()]);
|
|
|
|
}
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Allows adding [`SubCommand`] aliases, which function as "hidden" subcommands that
|
|
|
|
/// automatically dispatch as if this subcommand was used. This is more efficient, and easier
|
|
|
|
/// than creating multiple hidden subcommands as one only needs to check for the existing of
|
|
|
|
/// this command, and not all vairants.
|
2016-05-10 19:21:19 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
2016-05-11 18:14:17 +00:00
|
|
|
/// ```rust
|
2016-05-10 19:21:19 +00:00
|
|
|
/// # use clap::{App, Arg, SubCommand};
|
|
|
|
/// let m = App::new("myprog")
|
|
|
|
/// .subcommand(SubCommand::with_name("test")
|
|
|
|
/// .aliases(&["do-stuff", "do-tests", "tests"]))
|
2016-05-11 18:14:17 +00:00
|
|
|
/// .arg(Arg::with_name("input")
|
|
|
|
/// .help("the file to add")
|
|
|
|
/// .index(1)
|
2016-05-11 19:08:25 +00:00
|
|
|
/// .required(false))
|
2016-05-10 19:21:19 +00:00
|
|
|
/// .get_matches_from(vec!["myprog", "do-tests"]);
|
|
|
|
/// assert_eq!(m.subcommand_name(), Some("test"));
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`SubCommand`]: ./struct.SubCommand.html
|
2016-05-11 19:08:25 +00:00
|
|
|
pub fn aliases(mut self, names: &[&'b str]) -> Self {
|
2016-05-10 19:21:19 +00:00
|
|
|
if let Some(ref mut als) = self.p.meta.aliases {
|
|
|
|
for n in names {
|
2016-05-11 19:08:25 +00:00
|
|
|
als.push(n);
|
2016-05-10 19:21:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-05-11 19:08:25 +00:00
|
|
|
self.p.meta.aliases = Some(names.iter().map(|n| *n).collect::<Vec<_>>());
|
2016-05-10 19:21:19 +00:00
|
|
|
}
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Adds an [`ArgGroup`] to the application. [`ArgGroup`]s are a family of related arguments.
|
|
|
|
/// By placing them in a logical group, you can build easier requirement and exclusion rules.
|
|
|
|
/// For instance, you can make an entire [`ArgGroup`] required, meaning that one (and *only*
|
|
|
|
/// one) argument from that group must be present at runtime.
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
2016-05-14 20:25:00 +00:00
|
|
|
/// You can also do things such as name an [`ArgGroup`] as a conflict to another argument.
|
2016-01-26 19:02:10 +00:00
|
|
|
/// Meaning any of the arguments that belong to that group will cause a failure if present with
|
|
|
|
/// the conflicting argument.
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Another added benfit of [`ArgGroup`]s is that you can extract a value from a group instead
|
|
|
|
/// of determining exactly which argument was used.
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Finally, using [`ArgGroup`]s to ensure exclusion between arguments is another very common
|
|
|
|
/// use
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
2016-05-14 20:25:00 +00:00
|
|
|
/// The following example demonstrates using an [`ArgGroup`] to ensure that one, and only one,
|
|
|
|
/// of the arguments from the specified group is present at runtime.
|
2016-01-26 19:02:10 +00:00
|
|
|
///
|
2015-11-09 08:48:49 +00:00
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, ArgGroup};
|
2016-01-26 19:02:10 +00:00
|
|
|
/// App::new("app")
|
|
|
|
/// .args_from_usage(
|
|
|
|
/// "--set-ver [ver] 'set the version manually'
|
|
|
|
/// --major 'auto increase major'
|
|
|
|
/// --minor 'auto increase minor'
|
|
|
|
/// --patch 'auto increase patch'")
|
|
|
|
/// .group(ArgGroup::with_name("vers")
|
|
|
|
/// .args(&["set-ver", "major", "minor","patch"])
|
|
|
|
/// .required(true))
|
2015-11-09 08:48:49 +00:00
|
|
|
/// # ;
|
2016-01-26 19:02:10 +00:00
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`ArgGroup`]: ./struct.ArgGroup.html
|
2016-01-11 08:59:56 +00:00
|
|
|
pub fn group(mut self, group: ArgGroup<'a>) -> Self {
|
2016-02-04 16:54:46 +00:00
|
|
|
self.p.add_group(group);
|
2015-11-09 08:48:49 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Adds multiple [`ArgGroup`]s to the [`App`] at once.
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, ArgGroup};
|
2016-01-26 19:02:10 +00:00
|
|
|
/// App::new("app")
|
|
|
|
/// .args_from_usage(
|
|
|
|
/// "--set-ver [ver] 'set the version manually'
|
|
|
|
/// --major 'auto increase major'
|
|
|
|
/// --minor 'auto increase minor'
|
|
|
|
/// --patch 'auto increase patch'
|
|
|
|
/// -c [FILE] 'a config file'
|
|
|
|
/// -i [IFACE] 'an interface'")
|
|
|
|
/// .groups(&[
|
|
|
|
/// ArgGroup::with_name("vers")
|
|
|
|
/// .args(&["set-ver", "major", "minor","patch"])
|
|
|
|
/// .required(true),
|
|
|
|
/// ArgGroup::with_name("input")
|
|
|
|
/// .args(&["c", "i"])
|
|
|
|
/// ])
|
2015-11-09 08:48:49 +00:00
|
|
|
/// # ;
|
2016-01-26 19:02:10 +00:00
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`ArgGroup`]: ./struct.ArgGroup.html
|
|
|
|
/// [`App`]: ./struct.App.html
|
2016-01-11 08:59:56 +00:00
|
|
|
pub fn groups(mut self, groups: &[ArgGroup<'a>]) -> Self {
|
2015-11-09 08:48:49 +00:00
|
|
|
for g in groups {
|
2016-01-11 08:59:56 +00:00
|
|
|
self = self.group(g.into());
|
2015-11-09 08:48:49 +00:00
|
|
|
}
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Adds a [`SubCommand`] to the list of valid possibilties. Subcommands are effectively
|
|
|
|
/// sub-[`App`]s, because they can contain their own arguments, subcommands, version, usage,
|
|
|
|
/// etc. They also function just like [`App`]s, in that they get their own auto generated help,
|
|
|
|
/// version, and usage.
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg, SubCommand};
|
2016-01-26 19:02:10 +00:00
|
|
|
/// App::new("myprog")
|
|
|
|
/// .subcommand(SubCommand::with_name("config")
|
|
|
|
/// .about("Controls configuration features")
|
|
|
|
/// .arg_from_usage("<config> 'Required configuration file to use'"))
|
2015-11-09 08:48:49 +00:00
|
|
|
/// # ;
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`SubCommand`]: ./struct.SubCommand.html
|
|
|
|
/// [`App`]: ./struct.App.html
|
2016-01-11 08:59:56 +00:00
|
|
|
pub fn subcommand(mut self, subcmd: App<'a, 'b>) -> Self {
|
2016-02-04 16:54:46 +00:00
|
|
|
self.p.add_subcommand(subcmd);
|
2015-11-09 08:48:49 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Adds multiple subcommands to the list of valid possibilties by iterating over an
|
|
|
|
/// [`IntoIterator`] of [`SubCommand`]s
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
2016-05-14 20:25:00 +00:00
|
|
|
/// ```rust
|
2015-11-09 08:48:49 +00:00
|
|
|
/// # use clap::{App, Arg, SubCommand};
|
|
|
|
/// # App::new("myprog")
|
|
|
|
/// .subcommands( vec![
|
|
|
|
/// SubCommand::with_name("config").about("Controls configuration functionality")
|
|
|
|
/// .arg(Arg::with_name("config_file").index(1)),
|
|
|
|
/// SubCommand::with_name("debug").about("Controls debug functionality")])
|
|
|
|
/// # ;
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`SubCommand`]: ./struct.SubCommand.html
|
|
|
|
/// [`IntoIterator`]: https://doc.rust-lang.org/std/iter/trait.IntoIterator.html
|
2016-01-26 19:02:10 +00:00
|
|
|
pub fn subcommands<I>(mut self, subcmds: I) -> Self
|
|
|
|
where I: IntoIterator<Item = App<'a, 'b>>
|
|
|
|
{
|
2015-11-09 08:48:49 +00:00
|
|
|
for subcmd in subcmds.into_iter() {
|
2016-02-04 16:54:46 +00:00
|
|
|
self.p.add_subcommand(subcmd);
|
2015-11-09 08:48:49 +00:00
|
|
|
}
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Allows custom ordering of [`SubCommand`]s within the help message. Subcommands with a lower
|
2016-03-10 00:42:22 +00:00
|
|
|
/// value will be displayed first in the help message. This is helpful when one would like to
|
|
|
|
/// emphasise frequently used subcommands, or prioritize those towards the top of the list.
|
|
|
|
/// Duplicate values **are** allowed. Subcommands with duplicate display orders will be
|
|
|
|
/// displayed in alphabetical order.
|
|
|
|
///
|
|
|
|
/// **NOTE:** The default is 999 for all subcommands.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// # use clap::{App, SubCommand};
|
|
|
|
/// let m = App::new("cust-ord")
|
|
|
|
/// .subcommand(SubCommand::with_name("alpha") // typically subcommands are grouped
|
|
|
|
/// // alphabetically by name. Subcommands
|
|
|
|
/// // without a display_order have a value of
|
|
|
|
/// // 999 and are displayed alphabetically with
|
|
|
|
/// // all other 999 subcommands
|
|
|
|
/// .about("Some help and text"))
|
|
|
|
/// .subcommand(SubCommand::with_name("beta")
|
|
|
|
/// .display_order(1) // In order to force this subcommand to appear *first*
|
|
|
|
/// // all we have to do is give it a value lower than 999.
|
|
|
|
/// // Any other subcommands with a value of 1 will be displayed
|
|
|
|
/// // alphabetically with this one...then 2 values, then 3, etc.
|
|
|
|
/// .about("I should be first!"))
|
|
|
|
/// .get_matches_from(vec![
|
|
|
|
/// "cust-ord", "--help"
|
|
|
|
/// ]);
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
/// The above example displays the following help message
|
|
|
|
///
|
|
|
|
/// ```ignore
|
|
|
|
/// cust-ord
|
|
|
|
///
|
|
|
|
/// USAGE:
|
|
|
|
/// cust-ord [FLAGS] [OPTIONS]
|
|
|
|
///
|
|
|
|
/// FLAGS:
|
|
|
|
/// -h, --help Prints help information
|
|
|
|
/// -V, --version Prints version information
|
|
|
|
///
|
|
|
|
/// SUBCOMMANDS:
|
|
|
|
/// beta I should be first!
|
|
|
|
/// alpha Some help and text
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`SubCommand`]: ./struct.SubCommand.html
|
2016-03-10 00:42:22 +00:00
|
|
|
pub fn display_order(mut self, ord: usize) -> Self {
|
|
|
|
self.p.meta.disp_ord = ord;
|
|
|
|
self
|
|
|
|
}
|
2015-11-09 08:48:49 +00:00
|
|
|
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Prints the full help message to [`io::stdout()`] using a [`BufWriter`]
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
2016-01-26 19:02:10 +00:00
|
|
|
///
|
2016-05-14 20:25:00 +00:00
|
|
|
/// ```rust
|
2015-11-09 08:48:49 +00:00
|
|
|
/// # use clap::App;
|
2016-01-08 12:26:29 +00:00
|
|
|
/// let app = App::new("myprog");
|
|
|
|
/// app.print_help();
|
2015-11-09 08:48:49 +00:00
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`io::stdout()`]: https://doc.rust-lang.org/std/io/fn.stdout.html
|
|
|
|
/// [`BufWriter`]: https://doc.rust-lang.org/std/io/struct.BufWriter.html
|
2015-11-09 08:48:49 +00:00
|
|
|
pub fn print_help(&self) -> ClapResult<()> {
|
|
|
|
let out = io::stdout();
|
|
|
|
let mut buf_w = BufWriter::new(out.lock());
|
|
|
|
self.write_help(&mut buf_w)
|
|
|
|
}
|
|
|
|
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Writes the full help message to the user to a [`io::Write`] object
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// # Examples
|
|
|
|
///
|
2016-05-14 20:25:00 +00:00
|
|
|
/// ```rust
|
2015-11-09 08:48:49 +00:00
|
|
|
/// # use clap::App;
|
2016-01-26 19:02:10 +00:00
|
|
|
/// use std::io;
|
2015-11-09 08:48:49 +00:00
|
|
|
/// let mut app = App::new("myprog");
|
|
|
|
/// let mut out = io::stdout();
|
|
|
|
/// app.write_help(&mut out).ok().expect("failed to write to stdout");
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`io::Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
|
2015-11-09 08:48:49 +00:00
|
|
|
pub fn write_help<W: Write>(&self, w: &mut W) -> ClapResult<()> {
|
2016-04-01 06:00:11 +00:00
|
|
|
Help::write_app_help(w, &self)
|
2015-11-09 08:48:49 +00:00
|
|
|
}
|
|
|
|
|
2016-01-26 19:02:10 +00:00
|
|
|
/// Starts the parsing process, upon a failed parse an error will be displayed to the user and
|
2016-05-14 20:25:00 +00:00
|
|
|
/// the process with exit with the appropriate error code. By default this method gets all user
|
|
|
|
/// provided arguments from [`env::args_os`] in order to allow for invalid UTF-8 code points,
|
|
|
|
/// which are legal on many platforms.
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg};
|
|
|
|
/// let matches = App::new("myprog")
|
|
|
|
/// // Args and options go here...
|
|
|
|
/// .get_matches();
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`env::args_os`]: https://doc.rust-lang.org/std/env/fn.args_os.html
|
2016-01-21 05:18:53 +00:00
|
|
|
pub fn get_matches(self) -> ArgMatches<'a> {
|
2016-01-11 08:59:56 +00:00
|
|
|
self.get_matches_from(&mut env::args_os())
|
2015-11-09 08:48:49 +00:00
|
|
|
}
|
|
|
|
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Starts the parsing process. This method will return a [`clap::Result`] type instead of exiting
|
|
|
|
/// the the process on failed parse. By default this method gets matches from [`env::args_os`]
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// **NOTE:** This method WILL NOT exit when `--help` or `--version` (or short versions) are
|
2016-05-14 20:25:00 +00:00
|
|
|
/// used. It will return a [`clap::Error`], where the [`kind`] is a
|
|
|
|
/// [`ErrorKind::HelpDisplayed`] or [`ErrorKind::VersionDisplayed`] respectively. You must call
|
|
|
|
/// [`Error::exit`] or perform a [`std::process::exit`].
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg};
|
|
|
|
/// let matches = App::new("myprog")
|
|
|
|
/// // Args and options go here...
|
|
|
|
/// .get_matches_safe()
|
2016-01-26 19:02:10 +00:00
|
|
|
/// .unwrap_or_else( |e| e.exit() );
|
2015-11-09 08:48:49 +00:00
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`env::args_os`]: https://doc.rust-lang.org/std/env/fn.args_os.html
|
|
|
|
/// [`ErrorKind::HelpDisplayed`]: ./enum.ErrorKind.html#variant.HelpDisplayed
|
|
|
|
/// [`ErrorKind::VersionDisplayed`]: ./enum.ErrorKind.html#variant.VersionDisplayed
|
|
|
|
/// [`Error::exit`]: ./struct.Error.html#method.exit
|
|
|
|
/// [`std::process::exit`]: https://doc.rust-lang.org/std/process/fn.exit.html
|
|
|
|
/// [`clap::Result`]: ./type.Result.html
|
|
|
|
/// [`clap::Error`]: ./struct.Error.html
|
|
|
|
/// [`kind`]: ./struct.Error.html
|
2016-01-11 08:59:56 +00:00
|
|
|
pub fn get_matches_safe(self) -> ClapResult<ArgMatches<'a>> {
|
2015-11-09 08:48:49 +00:00
|
|
|
// Start the parsing
|
2016-01-11 08:59:56 +00:00
|
|
|
self.get_matches_from_safe(&mut env::args_os())
|
2015-11-09 08:48:49 +00:00
|
|
|
}
|
|
|
|
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Starts the parsing process. Like [`App::get_matches`] this method does not return a [`clap::Result`]
|
2016-01-26 19:02:10 +00:00
|
|
|
/// and will automatically exit with an error message. This method, however, lets you specify
|
2016-05-14 20:25:00 +00:00
|
|
|
/// what iterator to use when performing matches, such as a [`Vec`] of your making.
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// **NOTE:** The first argument will be parsed as the binary name unless
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`AppSettings::NoBinaryName`] is used
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg};
|
2016-01-11 08:59:56 +00:00
|
|
|
/// let arg_vec = vec!["my_prog", "some", "args", "to", "parse"];
|
|
|
|
///
|
2015-11-09 08:48:49 +00:00
|
|
|
/// let matches = App::new("myprog")
|
|
|
|
/// // Args and options go here...
|
2016-01-11 08:59:56 +00:00
|
|
|
/// .get_matches_from(arg_vec);
|
2015-11-09 08:48:49 +00:00
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`App::get_matches`]: ./struct.App.html#method.get_matches
|
|
|
|
/// [`clap::Result`]: ./type.Result.html
|
|
|
|
/// [`Vec`]: https://doc.rust-lang.org/std/vec/struct.Vec.html
|
|
|
|
/// [`AppSettings::NoBinaryName`]: ./enum.AppSettings.html#variant.NoBinaryName
|
2016-01-21 06:48:30 +00:00
|
|
|
pub fn get_matches_from<I, T>(mut self, itr: I) -> ArgMatches<'a>
|
|
|
|
where I: IntoIterator<Item = T>,
|
2016-01-11 08:59:56 +00:00
|
|
|
T: Into<OsString>
|
2015-11-09 08:48:49 +00:00
|
|
|
{
|
|
|
|
self.get_matches_from_safe_borrow(itr).unwrap_or_else(|e| {
|
|
|
|
// Otherwise, write to stderr and exit
|
|
|
|
self.maybe_wait_for_exit(e);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Starts the parsing process. A combination of [`App::get_matches_from`], and
|
|
|
|
/// [`App::get_matches_safe`]
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// **NOTE:** This method WILL NOT exit when `--help` or `--version` (or short versions) are
|
2016-05-14 20:25:00 +00:00
|
|
|
/// used. It will return a [`clap::Error`], where the [`kind`] is a [`ErrorKind::HelpDisplayed`]
|
|
|
|
/// or [`ErrorKind::VersionDisplayed`] respectively. You must call [`Error::exit`] or
|
|
|
|
/// perform a [`std::process::exit`] yourself.
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// **NOTE:** The first argument will be parsed as the binary name unless
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`AppSettings::NoBinaryName`] is used
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg};
|
|
|
|
/// let arg_vec = vec!["my_prog", "some", "args", "to", "parse"];
|
|
|
|
///
|
|
|
|
/// let matches = App::new("myprog")
|
|
|
|
/// // Args and options go here...
|
|
|
|
/// .get_matches_from_safe(arg_vec)
|
|
|
|
/// .unwrap_or_else( |e| { panic!("An error occurs: {}", e) });
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`App::get_matches_from`]: ./struct.App.html#method.get_matches_from
|
|
|
|
/// [`App::get_matches_safe`]: ./struct.App.html#method.get_matches_safe
|
|
|
|
/// [`ErrorKind::HelpDisplayed`]: ./enum.ErrorKind.html#variant.HelpDisplayed
|
|
|
|
/// [`ErrorKind::VersionDisplayed`]: ./enum.ErrorKind.html#variant.VersionDisplayed
|
|
|
|
/// [`Error::exit`]: ./struct.Error.html#method.exit
|
|
|
|
/// [`std::process::exit`]: https://doc.rust-lang.org/std/process/fn.exit.html
|
|
|
|
/// [`clap::Error`]: ./struct.Error.html
|
|
|
|
/// [`Error::exit`]: ./struct.Error.html#method.exit
|
|
|
|
/// [`kind`]: ./struct.Error.html
|
|
|
|
/// [`AppSettings::NoBinaryName`]: ./enum.AppSettings.html#variant.NoBinaryName
|
2016-01-21 06:48:30 +00:00
|
|
|
pub fn get_matches_from_safe<I, T>(mut self, itr: I) -> ClapResult<ArgMatches<'a>>
|
|
|
|
where I: IntoIterator<Item = T>,
|
2016-01-11 08:59:56 +00:00
|
|
|
T: Into<OsString>
|
2015-11-09 08:48:49 +00:00
|
|
|
{
|
|
|
|
self.get_matches_from_safe_borrow(itr)
|
|
|
|
}
|
|
|
|
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Starts the parsing process without consuming the [`App`] struct `self`. This is normally not
|
|
|
|
/// the desired functionality, instead prefer [`App::get_matches_from_safe`] which *does*
|
2015-11-09 08:48:49 +00:00
|
|
|
/// consume `self`.
|
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// **NOTE:** The first argument will be parsed as the binary name unless
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`AppSettings::NoBinaryName`] is used
|
2015-11-09 08:48:49 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg};
|
|
|
|
/// let arg_vec = vec!["my_prog", "some", "args", "to", "parse"];
|
|
|
|
///
|
|
|
|
/// let mut app = App::new("myprog");
|
|
|
|
/// // Args and options go here...
|
|
|
|
/// let matches = app.get_matches_from_safe_borrow(arg_vec)
|
|
|
|
/// .unwrap_or_else( |e| { panic!("An error occurs: {}", e) });
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`App`]: ./struct.App.html
|
|
|
|
/// [`App::get_matches_from_safe`]: ./struct.App.html#method.get_matches_from_safe
|
|
|
|
/// [`AppSettings::NoBinaryName`]: ./enum.AppSettings.html#variant.NoBinaryName
|
2016-01-21 06:48:30 +00:00
|
|
|
pub fn get_matches_from_safe_borrow<I, T>(&mut self, itr: I) -> ClapResult<ArgMatches<'a>>
|
|
|
|
where I: IntoIterator<Item = T>,
|
2016-01-11 08:59:56 +00:00
|
|
|
T: Into<OsString>
|
2015-11-09 08:48:49 +00:00
|
|
|
{
|
|
|
|
// Verify all positional assertions pass
|
2016-02-04 16:54:46 +00:00
|
|
|
self.p.verify_positionals();
|
2015-11-09 08:48:49 +00:00
|
|
|
// If there are global arguments, we need to propgate them down to subcommands
|
|
|
|
// before parsing incase we run into a subcommand
|
2016-02-04 16:54:46 +00:00
|
|
|
self.p.propogate_globals();
|
2015-11-09 08:48:49 +00:00
|
|
|
|
2015-11-09 13:57:20 +00:00
|
|
|
let mut matcher = ArgMatcher::new();
|
2015-11-09 08:48:49 +00:00
|
|
|
|
|
|
|
let mut it = itr.into_iter();
|
|
|
|
// Get the name of the program (argument 1 of env::args()) and determine the
|
|
|
|
// actual file
|
|
|
|
// that was used to execute the program. This is because a program called
|
|
|
|
// ./target/release/my_prog -a
|
|
|
|
// will have two arguments, './target/release/my_prog', '-a' but we don't want
|
|
|
|
// to display
|
|
|
|
// the full path when displaying help messages and such
|
2016-02-04 16:54:46 +00:00
|
|
|
if !self.p.is_set(AppSettings::NoBinaryName) {
|
2015-11-09 08:48:49 +00:00
|
|
|
if let Some(name) = it.next() {
|
2016-01-11 08:59:56 +00:00
|
|
|
let bn_os = name.into();
|
|
|
|
let p = Path::new(&*bn_os);
|
2015-11-09 08:48:49 +00:00
|
|
|
if let Some(f) = p.file_name() {
|
2016-01-11 08:59:56 +00:00
|
|
|
if let Some(s) = f.to_os_string().to_str() {
|
2016-02-04 16:54:46 +00:00
|
|
|
if let None = self.p.meta.bin_name {
|
|
|
|
self.p.meta.bin_name = Some(s.to_owned());
|
2015-11-09 08:48:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// do the real parsing
|
2016-02-04 16:54:46 +00:00
|
|
|
if let Err(e) = self.p.get_matches_with(&mut matcher, &mut it) {
|
2015-11-09 08:48:49 +00:00
|
|
|
return Err(e);
|
|
|
|
}
|
|
|
|
|
2015-11-09 13:57:20 +00:00
|
|
|
Ok(matcher.into())
|
2015-11-09 08:48:49 +00:00
|
|
|
}
|
|
|
|
|
2016-01-11 08:59:56 +00:00
|
|
|
// Re-implements ClapError::exit except it checks if we should wait for input before exiting
|
|
|
|
// since ClapError doesn't have that info and the error message must be printed before exiting
|
|
|
|
fn maybe_wait_for_exit(&self, e: Error) -> ! {
|
2015-11-09 08:48:49 +00:00
|
|
|
if e.use_stderr() {
|
2016-01-11 08:59:56 +00:00
|
|
|
wlnerr!("{}", e.message);
|
2016-02-04 16:54:46 +00:00
|
|
|
if self.p.is_set(AppSettings::WaitOnError) {
|
2015-11-09 08:48:49 +00:00
|
|
|
wlnerr!("\nPress [ENTER] / [RETURN] to continue...");
|
|
|
|
let mut s = String::new();
|
|
|
|
let i = io::stdin();
|
|
|
|
i.lock().read_line(&mut s).unwrap();
|
|
|
|
}
|
|
|
|
process::exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
e.exit()
|
|
|
|
}
|
|
|
|
}
|
2016-02-04 06:10:37 +00:00
|
|
|
|
|
|
|
#[cfg(feature = "yaml")]
|
|
|
|
impl<'a> From<&'a Yaml> for App<'a, 'a> {
|
|
|
|
fn from(mut yaml: &'a Yaml) -> Self {
|
|
|
|
use args::SubCommand;
|
|
|
|
// We WANT this to panic on error...so expect() is good.
|
|
|
|
let mut is_sc = None;
|
|
|
|
let mut a = if let Some(name) = yaml["name"].as_str() {
|
|
|
|
App::new(name)
|
|
|
|
} else {
|
|
|
|
let yaml_hash = yaml.as_hash().unwrap();
|
|
|
|
let sc_key = yaml_hash.keys().nth(0).unwrap();
|
|
|
|
is_sc = Some(yaml_hash.get(sc_key).unwrap());
|
|
|
|
App::new(sc_key.as_str().unwrap())
|
|
|
|
};
|
|
|
|
yaml = if let Some(sc) = is_sc {
|
|
|
|
sc
|
|
|
|
} else {
|
|
|
|
yaml
|
|
|
|
};
|
|
|
|
if let Some(v) = yaml["version"].as_str() {
|
|
|
|
a = a.version(v);
|
|
|
|
}
|
|
|
|
if let Some(v) = yaml["author"].as_str() {
|
|
|
|
a = a.author(v);
|
|
|
|
}
|
|
|
|
if let Some(v) = yaml["bin_name"].as_str() {
|
|
|
|
a = a.bin_name(v);
|
|
|
|
}
|
|
|
|
if let Some(v) = yaml["about"].as_str() {
|
|
|
|
a = a.about(v);
|
|
|
|
}
|
|
|
|
if let Some(v) = yaml["after_help"].as_str() {
|
|
|
|
a = a.after_help(v);
|
|
|
|
}
|
2016-03-10 01:14:35 +00:00
|
|
|
if let Some(v) = yaml["display_order"].as_i64() {
|
|
|
|
a = a.display_order(v as usize);
|
|
|
|
}
|
2016-02-04 06:10:37 +00:00
|
|
|
if let Some(v) = yaml["usage"].as_str() {
|
|
|
|
a = a.usage(v);
|
|
|
|
}
|
|
|
|
if let Some(v) = yaml["help"].as_str() {
|
|
|
|
a = a.help(v);
|
|
|
|
}
|
|
|
|
if let Some(v) = yaml["help_short"].as_str() {
|
|
|
|
a = a.help_short(v);
|
|
|
|
}
|
|
|
|
if let Some(v) = yaml["version_short"].as_str() {
|
|
|
|
a = a.version_short(v);
|
|
|
|
}
|
|
|
|
if let Some(v) = yaml["settings"].as_vec() {
|
|
|
|
for ys in v {
|
|
|
|
if let Some(s) = ys.as_str() {
|
|
|
|
a = a.setting(s.parse().ok().expect("unknown AppSetting found in YAML file"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-10 21:01:12 +00:00
|
|
|
if let Some(v) = yaml["aliases"].as_vec() {
|
|
|
|
for ys in v {
|
|
|
|
if let Some(s) = ys.as_str() {
|
|
|
|
a = a.alias(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-04 06:10:37 +00:00
|
|
|
if let Some(v) = yaml["args"].as_vec() {
|
|
|
|
for arg_yaml in v {
|
|
|
|
a = a.arg(Arg::from_yaml(&arg_yaml.as_hash().unwrap()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if let Some(v) = yaml["subcommands"].as_vec() {
|
|
|
|
for sc_yaml in v {
|
|
|
|
a = a.subcommand(SubCommand::from_yaml(&sc_yaml));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if let Some(v) = yaml["groups"].as_vec() {
|
|
|
|
for ag_yaml in v {
|
|
|
|
a = a.group(ArgGroup::from(ag_yaml.as_hash().unwrap()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
a
|
|
|
|
}
|
|
|
|
}
|
2016-03-15 02:09:17 +00:00
|
|
|
|
|
|
|
impl<'a, 'b> Clone for App<'a, 'b> {
|
|
|
|
fn clone(&self) -> Self {
|
2016-05-06 21:35:53 +00:00
|
|
|
App { p: self.p.clone() }
|
2016-03-15 02:09:17 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-16 14:17:00 +00:00
|
|
|
|
|
|
|
impl<'n, 'e> AnyArg<'n, 'e> for App<'n, 'e> {
|
|
|
|
fn name(&self) -> &'n str {
|
|
|
|
unreachable!("App struct does not support AnyArg::name, this is a bug!")
|
|
|
|
}
|
2016-05-06 21:35:53 +00:00
|
|
|
fn overrides(&self) -> Option<&[&'e str]> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
fn requires(&self) -> Option<&[&'e str]> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
fn blacklist(&self) -> Option<&[&'e str]> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
fn required_unless(&self) -> Option<&[&'e str]> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
fn val_names(&self) -> Option<&VecMap<&'e str>> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
fn is_set(&self, _: ArgSettings) -> bool {
|
|
|
|
false
|
|
|
|
}
|
2016-03-16 14:17:00 +00:00
|
|
|
fn set(&mut self, _: ArgSettings) {
|
|
|
|
unreachable!("App struct does not support AnyArg::set, this is a bug!")
|
|
|
|
}
|
2016-05-06 21:35:53 +00:00
|
|
|
fn has_switch(&self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
fn max_vals(&self) -> Option<u64> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
fn num_vals(&self) -> Option<u64> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
fn possible_vals(&self) -> Option<&[&'e str]> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
fn validator(&self) -> Option<&Rc<Fn(String) -> StdResult<(), String>>> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
fn min_vals(&self) -> Option<u64> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
fn short(&self) -> Option<char> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
fn long(&self) -> Option<&'e str> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
fn val_delim(&self) -> Option<char> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
fn takes_value(&self) -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
fn help(&self) -> Option<&'e str> {
|
|
|
|
self.p.meta.about
|
|
|
|
}
|
|
|
|
fn default_val(&self) -> Option<&'n str> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
fn longest_filter(&self) -> bool {
|
|
|
|
true
|
|
|
|
}
|
2016-03-16 14:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'n, 'e> fmt::Display for App<'n, 'e> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "{}", self.p.meta.name)
|
|
|
|
}
|
|
|
|
}
|