name | The name displayed to the user when showing version and help/usage information
@@ -119,46 +119,46 @@ showing the usage.
Adds an argument to the list of valid possibilties
- # Example
-
- .arg(Arg::new("config")
- .short("c")
+
+.arg(Arg::new("config")
+ .short("c")
- )
+)
Adds multiple arguments to the list of valid possibilties
- # Example
-
- .args( vec![Arg::new("config").short("c"),
- Arg::new("debug").short("d")])
+
+.args( vec![Arg::new("config").short("c"),
+ Arg::new("debug").short("d")])
Adds a subcommand to the list of valid possibilties. Subcommands
- are effectively sub apps, because they can contain their own arguments
- and subcommands. They also function just like apps, in that they get their
- own auto generated help and version switches.
+are effectively sub apps, because they can contain their own arguments
+and subcommands. They also function just like apps, in that they get their
+own auto generated help and version switches.
- # Example
-
- .subcommand(SubCommand::new("config")
- .about("Controls configuration features")
- .arg(Arg::new("config_file")
- .index(1)
- .help("Configuration file to use")))
+
+.subcommand(SubCommand::new("config")
+ .about("Controls configuration features")
+ .arg(Arg::new("config_file")
+ .index(1)
+ .help("Configuration file to use")))
- )
+)
Adds multiple subcommands to the list of valid possibilties
- # Example
-
- .subcommands( vec![
- SubCommand::new("config").about("Controls configuration functionality")
- .arg(Arg::new("config_file").index(1)),
- SubCommand::new("debug").about("Controls debug functionality")])
+
+.subcommands( vec![
+ SubCommand::new("config").about("Controls configuration functionality")
+ .arg(Arg::new("config_file").index(1)),
+ SubCommand::new("debug").about("Controls debug functionality")])
diff --git a/docs/clap/struct.Arg.html b/docs/clap/struct.Arg.html
index d345f105..5eabb9cf 100644
--- a/docs/clap/struct.Arg.html
+++ b/docs/clap/struct.Arg.html
@@ -170,16 +170,16 @@ arguments, they do not need to be set for each.
Sets a mutually exclusive arguments by names. I.e. when using this argument,
- the following argument can't be present.
+the following argument can't be present.
NOTE: Mutually exclusive rules take precedence over being required
- by default. Mutually exclusive rules only need to be set for one of the two
- arguments, they do not need to be set for each.
+by default. Mutually exclusive rules only need to be set for one of the two
+arguments, they do not need to be set for each.
Example:
- .mutually_excludes_all(
- vec!["debug", "input"])
+.mutually_excludes_all(
+ vec!["debug", "input"])
fn requires(self, name: &'static str) -> Arg
Sets an argument by name that is required when this one is presnet I.e. when
@@ -193,15 +193,15 @@ using this argument, the following argument must be present.
Sets arguments by names that are required when this one is presnet I.e. when
- using this argument, the following arguments must be present.
+using this argument, the following arguments must be present.
NOTE: Mutually exclusive rules take precedence over being required
- by default.
+by default.
Example:
- .requires_all(
- vec!["debug", "input"])
+.requires_all(
+ vec!["debug", "input"])
Specifies that the argument takes an additional value at run time.
diff --git a/docs/clap/struct.SubCommand.html b/docs/clap/struct.SubCommand.html
index c267ff68..7f917f56 100644
--- a/docs/clap/struct.SubCommand.html
+++ b/docs/clap/struct.SubCommand.html
@@ -50,16 +50,16 @@
} The abstract representation of a command line subcommand used by the consumer of the library.
This struct is used by the library consumer and describes all the valid options of the subcommand for
- their program. SubCommands are treated like "sub apps" and contain all the same possibilities (such as
- their own arguments and subcommands).
+their program. SubCommands are treated like "sub apps" and contain all the same possibilities (such as
+their own arguments and subcommands).
- # Example
-
- SubCommand::new("conifg")
- .about("Used for configuration")
- .arg(Arg::new("config_file")
- .help("The configuration file to use")
- .index(1))
+
+SubCommand::new("conifg")
+ .about("Used for configuration")
+ .arg(Arg::new("config_file")
+ .help("The configuration file to use")
+ .index(1))
Fields
Methodsfn new(name: &'static str) -> App
diff --git a/docs/search-index.js b/docs/search-index.js
index 180bb2bd..d719f2de 100644
--- a/docs/search-index.js
+++ b/docs/search-index.js
@@ -1,3 +1,3 @@
var searchIndex = {};
-searchIndex['clap'] = {"items":[[0,"","clap","A simply library for parsing command line arguments when writing\n command line and console applications."],[3,"ArgMatches","","Used to get information about the arguments that\nwhere supplied to the program at runtime."],[12,"matches_of","","",0],[12,"flags","","",0],[12,"opts","","",0],[12,"positionals","","",0],[12,"subcommand","","",0],[3,"Arg","","The abstract representation of a command line argument used by the consumer of the library.\n "],[12,"name","","The unique name of the argument, required",1],[12,"short","","The short version (i.e. single character) of the argument, no preceding `-`\n**NOTE:** `short` is mutually exclusive with `index`",1],[12,"long","","The long version of the flag (i.e. word) without the preceding `--`\n**NOTE:** `long` is mutually exclusive with `index`",1],[12,"help","","The string of text that will displayed to the user when the application's\n`help` text is displayed",1],[12,"required","","If this is a required by default when using the command line program\ni.e. a configuration file that's required for the program to function\n**NOTE:** required by default means, it is required *until* mutually\nexclusive arguments are evaluated.",1],[12,"takes_value","","Determines if this argument is an option, vice a flag or positional and\nis mutually exclusive with `index` and `multiple`",1],[12,"index","","The index of the argument. `index` is mutually exclusive with `takes_value`\nand `multiple`",1],[12,"multiple","","Determines if multiple instances of the same flag are allowed. `multiple`\nis mutually exclusive with `index` and `takes_value`.\nI.e. `-v -v -v` or `-vvv`",1],[12,"blacklist","","A list of names for other arguments that *may not* be used with this flag",1],[12,"requires","","A list of names of other arguments that are *required* to be used when\nthis flag is used",1],[3,"App","","Used to create a representation of the program and all possible command line arguments\n for parsing at runtime."],[12,"name","","The name displayed to the user when showing version and help/usage information",2],[12,"author","","A string of author(s) if desired. Displayed when showing help/usage information",2],[12,"version","","The version displayed to the user",2],[12,"about","","A brief explaination of the program that gets displayed to the user when shown help/usage information",2],[3,"SubCommand","","The abstract representation of a command line subcommand used by the consumer of the library.\n "],[12,"name","","",3],[12,"matches","","",3],[11,"new","","Creates a new instance of an application requiring a name (such as the binary). Will be displayed\nto the user when they print version or help and usage information.",2],[11,"author","","Sets a string of author(s)",2],[11,"about","","Sets a string briefly describing what the program does",2],[11,"version","","Sets a string of the version number",2],[11,"usage","","Sets a custom usage string to over-ride the one auto-generated by `clap`\n*NOTE:* You do not need to specify the \"USAGE: \" portion, as that will \nstill be applied by `clap`, you only need to specify the portion starting\nwith the binary name. \n*NOTE:* This will not replace the entire help message, only the portion\nshowing the usage.",2],[11,"arg","","Adds an argument to the list of valid possibilties",2],[11,"args","","Adds multiple arguments to the list of valid possibilties",2],[11,"subcommand","","Adds a subcommand to the list of valid possibilties. Subcommands\n are effectively sub apps, because they can contain their own arguments\n and subcommands. They also function just like apps, in that they get their\n own auto generated help and version switches.",2],[11,"subcommands","","Adds multiple subcommands to the list of valid possibilties",2],[11,"get_matches","","",2],[11,"new","","Creates a new instance of `ArgMatches`. This ins't called directly, but\nthrough the `.get_matches()` method of `App`",0],[11,"value_of","","Gets the value of a specific option or positional argument (i.e. an argument that takes\nan additional value at runtime). If the option wasn't present at runtime\nit returns `None`",0],[11,"is_present","","Checks if a flag was argument was supplied at runtime. **DOES NOT** work for\noption or positional arguments (use `.value_of()` instead)",0],[11,"occurrences_of","","Checks the number of occurrences of a flag at runtime.",0],[11,"subcommand_matches","","If a subcommand was found, returns the ArgMatches struct associated with it's matches",0],[11,"subcommand_name","","If a subcommand was found, returns the name associated with it",0],[11,"new","","Creates a new instace of `Arg` using a unique string name.\nThe name will be used by the library consumer to get information about\nwhether or not the argument was used at runtime. ",1],[11,"short","","Sets the short version of the argument without the preceding `-`.",1],[11,"long","","Sets the long version of the argument without the preceding `--`.",1],[11,"help","","Sets the help text of the argument that will be displayed to the user\nwhen they print the usage/help information. ",1],[11,"required","","Sets whether or not the argument is required by default. Required by\ndefault means it is required, when no other mutually exlusive rules have\nbeen evaluated. Mutually exclusive rules take precedence over being required\nby default.",1],[11,"mutually_excludes","","Sets a mutually exclusive argument by name. I.e. when using this argument,\nthe following argument can't be present.",1],[11,"mutually_excludes_all","","Sets a mutually exclusive arguments by names. I.e. when using this argument,\n the following argument can't be present.",1],[11,"requires","","Sets an argument by name that is required when this one is presnet I.e. when\nusing this argument, the following argument *must* be present.",1],[11,"requires_all","","Sets arguments by names that are required when this one is presnet I.e. when\n using this argument, the following arguments *must* be present.",1],[11,"takes_value","","Specifies that the argument takes an additional value at run time.\n \n**NOTE:** When setting this to `true` the `name` of the argument\nwill be used when printing the help/usage information to the user. ",1],[11,"index","","Specifies the index of a positional argument starting at 1.\n \n**NOTE:** When setting this, any `short` or `long` values you set\nare ignored as positional arguments cannot have a `short` or `long`.\nAlso, the name will be used when printing the help/usage information \nto the user. ",1],[11,"multiple","","Specifies if the flag may appear more than once such as for multiple debugging\nlevels (as an example). `-ddd` for three levels of debugging, or `-d -d -d`. \nWhen this is set to `true` you recieve the number of occurances the user supplied\nof a particular flag at runtime.\n \n**NOTE:** When setting this, any `takes_value` or `index` values you set\nare ignored as flags cannot have a values or an `index`.",1],[11,"new","","Creates a new instance of a subcommand requiring a name. Will be displayed\nto the user when they print version or help and usage information.",3]],"paths":[[3,"ArgMatches"],[3,"Arg"],[3,"App"],[3,"SubCommand"]]};
+searchIndex['clap'] = {"items":[[0,"","clap","A simply library for parsing command line arguments when writing\ncommand line and console applications."],[3,"ArgMatches","","Used to get information about the arguments that\nwhere supplied to the program at runtime."],[12,"matches_of","","",0],[12,"flags","","",0],[12,"opts","","",0],[12,"positionals","","",0],[12,"subcommand","","",0],[3,"Arg","","The abstract representation of a command line argument used by the consumer of the library.\n "],[12,"name","","The unique name of the argument, required",1],[12,"short","","The short version (i.e. single character) of the argument, no preceding `-`\n**NOTE:** `short` is mutually exclusive with `index`",1],[12,"long","","The long version of the flag (i.e. word) without the preceding `--`\n**NOTE:** `long` is mutually exclusive with `index`",1],[12,"help","","The string of text that will displayed to the user when the application's\n`help` text is displayed",1],[12,"required","","If this is a required by default when using the command line program\ni.e. a configuration file that's required for the program to function\n**NOTE:** required by default means, it is required *until* mutually\nexclusive arguments are evaluated.",1],[12,"takes_value","","Determines if this argument is an option, vice a flag or positional and\nis mutually exclusive with `index` and `multiple`",1],[12,"index","","The index of the argument. `index` is mutually exclusive with `takes_value`\nand `multiple`",1],[12,"multiple","","Determines if multiple instances of the same flag are allowed. `multiple`\nis mutually exclusive with `index` and `takes_value`.\nI.e. `-v -v -v` or `-vvv`",1],[12,"blacklist","","A list of names for other arguments that *may not* be used with this flag",1],[12,"requires","","A list of names of other arguments that are *required* to be used when\nthis flag is used",1],[3,"App","","Used to create a representation of the program and all possible command line arguments\nfor parsing at runtime."],[12,"name","","The name displayed to the user when showing version and help/usage information",2],[12,"author","","A string of author(s) if desired. Displayed when showing help/usage information",2],[12,"version","","The version displayed to the user",2],[12,"about","","A brief explaination of the program that gets displayed to the user when shown help/usage information",2],[3,"SubCommand","","The abstract representation of a command line subcommand used by the consumer of the library.\n "],[12,"name","","",3],[12,"matches","","",3],[11,"new","","Creates a new instance of an application requiring a name (such as the binary). Will be displayed\nto the user when they print version or help and usage information.",2],[11,"author","","Sets a string of author(s)",2],[11,"about","","Sets a string briefly describing what the program does",2],[11,"version","","Sets a string of the version number",2],[11,"usage","","Sets a custom usage string to over-ride the one auto-generated by `clap`\n*NOTE:* You do not need to specify the \"USAGE: \" portion, as that will \nstill be applied by `clap`, you only need to specify the portion starting\nwith the binary name. \n*NOTE:* This will not replace the entire help message, only the portion\nshowing the usage.",2],[11,"arg","","Adds an argument to the list of valid possibilties",2],[11,"args","","Adds multiple arguments to the list of valid possibilties",2],[11,"subcommand","","Adds a subcommand to the list of valid possibilties. Subcommands\nare effectively sub apps, because they can contain their own arguments\nand subcommands. They also function just like apps, in that they get their\nown auto generated help and version switches.",2],[11,"subcommands","","Adds multiple subcommands to the list of valid possibilties",2],[11,"get_matches","","",2],[11,"new","","Creates a new instance of `ArgMatches`. This ins't called directly, but\nthrough the `.get_matches()` method of `App`",0],[11,"value_of","","Gets the value of a specific option or positional argument (i.e. an argument that takes\nan additional value at runtime). If the option wasn't present at runtime\nit returns `None`",0],[11,"is_present","","Checks if a flag was argument was supplied at runtime. **DOES NOT** work for\noption or positional arguments (use `.value_of()` instead)",0],[11,"occurrences_of","","Checks the number of occurrences of a flag at runtime.",0],[11,"subcommand_matches","","If a subcommand was found, returns the ArgMatches struct associated with it's matches",0],[11,"subcommand_name","","If a subcommand was found, returns the name associated with it",0],[11,"new","","Creates a new instace of `Arg` using a unique string name.\nThe name will be used by the library consumer to get information about\nwhether or not the argument was used at runtime. ",1],[11,"short","","Sets the short version of the argument without the preceding `-`.",1],[11,"long","","Sets the long version of the argument without the preceding `--`.",1],[11,"help","","Sets the help text of the argument that will be displayed to the user\nwhen they print the usage/help information. ",1],[11,"required","","Sets whether or not the argument is required by default. Required by\ndefault means it is required, when no other mutually exlusive rules have\nbeen evaluated. Mutually exclusive rules take precedence over being required\nby default.",1],[11,"mutually_excludes","","Sets a mutually exclusive argument by name. I.e. when using this argument,\nthe following argument can't be present.",1],[11,"mutually_excludes_all","","Sets a mutually exclusive arguments by names. I.e. when using this argument,\nthe following argument can't be present.",1],[11,"requires","","Sets an argument by name that is required when this one is presnet I.e. when\nusing this argument, the following argument *must* be present.",1],[11,"requires_all","","Sets arguments by names that are required when this one is presnet I.e. when\nusing this argument, the following arguments *must* be present.",1],[11,"takes_value","","Specifies that the argument takes an additional value at run time.\n \n**NOTE:** When setting this to `true` the `name` of the argument\nwill be used when printing the help/usage information to the user. ",1],[11,"index","","Specifies the index of a positional argument starting at 1.\n \n**NOTE:** When setting this, any `short` or `long` values you set\nare ignored as positional arguments cannot have a `short` or `long`.\nAlso, the name will be used when printing the help/usage information \nto the user. ",1],[11,"multiple","","Specifies if the flag may appear more than once such as for multiple debugging\nlevels (as an example). `-ddd` for three levels of debugging, or `-d -d -d`. \nWhen this is set to `true` you recieve the number of occurances the user supplied\nof a particular flag at runtime.\n \n**NOTE:** When setting this, any `takes_value` or `index` values you set\nare ignored as flags cannot have a values or an `index`.",1],[11,"new","","Creates a new instance of a subcommand requiring a name. Will be displayed\nto the user when they print version or help and usage information.",3]],"paths":[[3,"ArgMatches"],[3,"Arg"],[3,"App"],[3,"SubCommand"]]};
initSearch(searchIndex);
diff --git a/docs/src/clap/app.rs/app.rs.html b/docs/src/clap/app.rs/app.rs.html
index 64001b45..7c3267f9 100644
--- a/docs/src/clap/app.rs/app.rs.html
+++ b/docs/src/clap/app.rs/app.rs.html
@@ -936,10 +936,10 @@
-
+
-
+
@@ -947,831 +947,831 @@
pub struct App {
-
- pub name: &'static str,
-
- pub author: Option<&'static str>,
-
- pub version: Option<&'static str>,
-
- pub about: Option<&'static str>,
- flags: HashMap<&'static str, FlagArg>,
- opts: HashMap<&'static str, OptArg>,
- positionals_idx: BTreeMap<u8, PosArg>,
- subcommands: HashMap<&'static str, Box<App>>,
-
- needs_long_help: bool,
- needs_long_version: bool,
- needs_short_help: bool,
- needs_short_version: bool,
- needs_subcmd_help: bool,
- required: HashSet<&'static str>,
- arg_list: HashSet<&'static str>,
- short_list: HashSet<char>,
- long_list: HashSet<&'static str>,
- blacklist: HashSet<&'static str>,
- usage_str: Option<&'static str>,
- bin_name: Option<String>
+
+ pub name: &'static str,
+
+ pub author: Option<&'static str>,
+
+ pub version: Option<&'static str>,
+
+ pub about: Option<&'static str>,
+ flags: HashMap<&'static str, FlagArg>,
+ opts: HashMap<&'static str, OptArg>,
+ positionals_idx: BTreeMap<u8, PosArg>,
+ subcommands: HashMap<&'static str, Box<App>>,
+
+ needs_long_help: bool,
+ needs_long_version: bool,
+ needs_short_help: bool,
+ needs_short_version: bool,
+ needs_subcmd_help: bool,
+ required: HashSet<&'static str>,
+ arg_list: HashSet<&'static str>,
+ short_list: HashSet<char>,
+ long_list: HashSet<&'static str>,
+ blacklist: HashSet<&'static str>,
+ usage_str: Option<&'static str>,
+ bin_name: Option<String>
}
impl App {
-
-
-
-
-
-
-
-
-
-
- pub fn new( n: &'static str) -> App {
- App {
- name: n,
- author: None,
- about: None,
- version: None,
- flags: HashMap:: new(),
- opts: HashMap:: new(),
- positionals_idx: BTreeMap:: new(),
- subcommands: HashMap:: new(),
-
- needs_long_version: true,
- needs_long_help: true,
- needs_short_help: true,
- needs_subcmd_help: true,
- needs_short_version: true,
- required: HashSet:: new(),
- arg_list: HashSet:: new(),
- short_list: HashSet:: new(),
- long_list: HashSet:: new(),
- usage_str: None,
- blacklist: HashSet:: new(),
- bin_name: None,
- }
- }
+
+
+
+
+
+
+
+
+
+
+ pub fn new( n: &'static str) -> App {
+ App {
+ name: n,
+ author: None,
+ about: None,
+ version: None,
+ flags: HashMap:: new(),
+ opts: HashMap:: new(),
+ positionals_idx: BTreeMap:: new(),
+ subcommands: HashMap:: new(),
+
+ needs_long_version: true,
+ needs_long_help: true,
+ needs_short_help: true,
+ needs_subcmd_help: true,
+ needs_short_version: true,
+ required: HashSet:: new(),
+ arg_list: HashSet:: new(),
+ short_list: HashSet:: new(),
+ long_list: HashSet:: new(),
+ usage_str: None,
+ blacklist: HashSet:: new(),
+ bin_name: None,
+ }
+ }
-
-
-
-
-
-
-
-
-
-
- pub fn author( mut self, a: &'static str) -> App {
- self. author = Some( a);
- self
- }
+
+
+
+
+
+
+
+
+
+
+ pub fn author( mut self, a: &'static str) -> App {
+ self. author = Some( a);
+ self
+ }
-
-
-
-
-
-
-
-
-
-
- pub fn about( mut self, a: &'static str) -> App {
- self. about = Some( a);
- self
- }
+
+
+
+
+
+
+
+
+
+
+ pub fn about( mut self, a: &'static str) -> App {
+ self. about = Some( a);
+ self
+ }
-
-
-
-
-
-
-
-
-
-
- pub fn version( mut self, v: &'static str) -> App {
- self. version = Some( v);
- self
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- pub fn usage( mut self, u: &'static str) -> App {
- self. usage_str = Some( u);
- self
- }
+
+
+
+
+
+
+
+
+
+
+ pub fn version( mut self, v: &'static str) -> App {
+ self. version = Some( v);
+ self
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pub fn usage( mut self, u: &'static str) -> App {
+ self. usage_str = Some( u);
+ self
+ }
-
-
-
-
-
-
-
-
-
-
-
-
-
- pub fn arg( mut self, a: Arg) -> App {
- if self. arg_list. contains( a. name) {
- panic!( "Argument name must be unique, \"{}\" is already in use", a. name);
- } else {
- self. arg_list. insert( a. name);
- }
- if let Some( ref s) = a. short {
- if self. short_list. contains( s) {
- panic!( "Argument short must be unique, -{} is already in use", s);
- } else {
- self. short_list. insert( *s);
- }
- }
- if let Some( ref l) = a. long {
- if self. long_list. contains( l) {
- panic!( "Argument long must be unique, --{} is already in use", l);
- } else {
- self. long_list. insert( l);
- }
- }
- if a. required {
- self. required. insert( a. name);
- }
- if let Some( i) = a. index {
- self. positionals_idx. insert( i, PosArg {
- name: a. name,
- index: i,
- required: a. required,
- blacklist: a. blacklist,
- requires: a. requires,
- help: a. help,
- value: None
- });
- } else if a. takes_value {
- if a. short == None && a. long == None {
- panic!( "An argument that takes a value must have either a .short() or .long() [or both] assigned");
- }
- self. opts. insert( a. name, OptArg {
- name: a. name,
- short: a. short,
- long: a. long,
- blacklist: a. blacklist,
- help: a. help,
- requires: a. requires,
- required: a. required,
- value: None
- });
- } else {
- if let Some( ref l) = a. long {
- if *l == "help" {
- self. needs_long_help = false;
- } else if *l == "version" {
- self. needs_long_version = false;
- }
- }
- if let Some( ref s) = a. short {
- if *s == 'h' {
- self. needs_short_help = false;
- } else if *s == 'v' {
- self. needs_short_version = false;
- }
- }
- if a. short == None && a. long == None {
- panic!( "A flag argument must have either a .short() or .long() [or both] assigned");
- }
-
- if self. required. contains( a. name) {
- self. required. remove( a. name);
- }
- self. flags. insert( a. name, FlagArg{
- name: a. name,
- short: a. short,
- long: a. long,
- help: a. help,
- blacklist: a. blacklist,
- multiple: a. multiple,
- requires: a. requires,
- occurrences: 1
- });
- }
- self
- }
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pub fn arg( mut self, a: Arg) -> App {
+ if self. arg_list. contains( a. name) {
+ panic!( "Argument name must be unique, \"{}\" is already in use", a. name);
+ } else {
+ self. arg_list. insert( a. name);
+ }
+ if let Some( ref s) = a. short {
+ if self. short_list. contains( s) {
+ panic!( "Argument short must be unique, -{} is already in use", s);
+ } else {
+ self. short_list. insert( *s);
+ }
+ }
+ if let Some( ref l) = a. long {
+ if self. long_list. contains( l) {
+ panic!( "Argument long must be unique, --{} is already in use", l);
+ } else {
+ self. long_list. insert( l);
+ }
+ }
+ if a. required {
+ self. required. insert( a. name);
+ }
+ if let Some( i) = a. index {
+ self. positionals_idx. insert( i, PosArg {
+ name: a. name,
+ index: i,
+ required: a. required,
+ blacklist: a. blacklist,
+ requires: a. requires,
+ help: a. help,
+ value: None
+ });
+ } else if a. takes_value {
+ if a. short == None && a. long == None {
+ panic!( "An argument that takes a value must have either a .short() or .long() [or both] assigned");
+ }
+ self. opts. insert( a. name, OptArg {
+ name: a. name,
+ short: a. short,
+ long: a. long,
+ blacklist: a. blacklist,
+ help: a. help,
+ requires: a. requires,
+ required: a. required,
+ value: None
+ });
+ } else {
+ if let Some( ref l) = a. long {
+ if *l == "help" {
+ self. needs_long_help = false;
+ } else if *l == "version" {
+ self. needs_long_version = false;
+ }
+ }
+ if let Some( ref s) = a. short {
+ if *s == 'h' {
+ self. needs_short_help = false;
+ } else if *s == 'v' {
+ self. needs_short_version = false;
+ }
+ }
+ if a. short == None && a. long == None {
+ panic!( "A flag argument must have either a .short() or .long() [or both] assigned");
+ }
+
+ if self. required. contains( a. name) {
+ self. required. remove( a. name);
+ }
+ self. flags. insert( a. name, FlagArg{
+ name: a. name,
+ short: a. short,
+ long: a. long,
+ help: a. help,
+ blacklist: a. blacklist,
+ multiple: a. multiple,
+ requires: a. requires,
+ occurrences: 1
+ });
+ }
+ self
+ }
-
-
-
-
-
-
-
-
-
-
-
- pub fn args( mut self, args: Vec<Arg>) -> App {
- for arg in args. into_iter() {
- self = self. arg( arg);
- }
- self
- }
+
+
+
+
+
+
+
+
+
+
+
+ pub fn args( mut self, args: Vec<Arg>) -> App {
+ for arg in args. into_iter() {
+ self = self. arg( arg);
+ }
+ self
+ }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- pub fn subcommand( mut self, subcmd: App) -> App {
- if subcmd. name == "help" { self. needs_subcmd_help = false; }
- self. subcommands. insert( subcmd. name, Box:: new( subcmd));
- self
- }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pub fn subcommand( mut self, subcmd: App) -> App {
+ if subcmd. name == "help" { self. needs_subcmd_help = false; }
+ self. subcommands. insert( subcmd. name, Box:: new( subcmd));
+ self
+ }
-
-
-
-
-
-
-
-
-
-
-
-
-
- pub fn subcommands( mut self, subcmds: Vec<App>) -> App {
- for subcmd in subcmds. into_iter() {
- self = self. subcommand( subcmd);
- }
- self
- }
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pub fn subcommands( mut self, subcmds: Vec<App>) -> App {
+ for subcmd in subcmds. into_iter() {
+ self = self. subcommand( subcmd);
+ }
+ self
+ }
- fn exit( &self) {
- unsafe { libc:: exit( 0); }
- }
+ fn exit( &self) {
+ unsafe { libc:: exit( 0); }
+ }
- fn report_error( &self, msg: String, help: bool, quit: bool) {
- println!( "{}", msg);
- if help { self. print_usage( true); }
- if quit { env:: set_exit_status( 1); self. exit(); }
- }
+ fn report_error( &self, msg: String, help: bool, quit: bool) {
+ println!( "{}", msg);
+ if help { self. print_usage( true); }
+ if quit { env:: set_exit_status( 1); self. exit(); }
+ }
- fn print_usage( &self, more_info: bool) {
- println!( "USAGE:");
- if let Some( u) = self. usage_str {
- println!( "\t{}", u);
- } else {
- let flags = ! self. flags. is_empty();
- let pos = ! self. positionals_idx. is_empty();
- let req_pos = self. positionals_idx. values(). filter_map( |ref x| if x. required { Some( x. name) } else { None})
- . fold( String:: new(), |acc, ref name| acc + &format!( "<{}> ", name. to_uppercase())[..]);
- let req_opts = self. opts. values(). filter( |ref x| x. required)
- . fold( String:: new(), |acc, ref o| acc + &format!( "{}{} ", if let Some( s) = o. short {
- format!( "-{} ", s)
- } else {
- format!( "--{}=", o. long. unwrap())
- }, o. name. to_uppercase()));
- let opts = ! self. opts. is_empty();
- let subcmds = ! self. subcommands. is_empty();
+ fn print_usage( &self, more_info: bool) {
+ println!( "USAGE:");
+ if let Some( u) = self. usage_str {
+ println!( "\t{}", u);
+ } else {
+ let flags = ! self. flags. is_empty();
+ let pos = ! self. positionals_idx. is_empty();
+ let req_pos = self. positionals_idx. values(). filter_map( |ref x| if x. required { Some( x. name) } else { None})
+ . fold( String:: new(), |acc, ref name| acc + &format!( "<{}> ", name. to_uppercase())[..]);
+ let req_opts = self. opts. values(). filter( |ref x| x. required)
+ . fold( String:: new(), |acc, ref o| acc + &format!( "{}{} ", if let Some( s) = o. short {
+ format!( "-{} ", s)
+ } else {
+ format!( "--{}=", o. long. unwrap())
+ }, o. name. to_uppercase()));
+ let opts = ! self. opts. is_empty();
+ let subcmds = ! self. subcommands. is_empty();
- print!( "\t{} {} {} {} {}", if let Some( ref name) = self. bin_name { &name[..] } else { self. name },
- if flags { "[FLAGS]"} else { ""},
- if opts {
- if req_opts. is_empty() { "[OPTIONS]" } else { &req_opts[..] }
- } else { "" },
- if pos {
- if req_pos. is_empty() { "[POSITIONAL]"} else { &req_pos[..] }
- } else { ""},
- if subcmds { "[SUBCOMMANDS]"} else { ""});
- }
+ print!( "\t{} {} {} {} {}", if let Some( ref name) = self. bin_name { &name[..] } else { self. name },
+ if flags { "[FLAGS]"} else { ""},
+ if opts {
+ if req_opts. is_empty() { "[OPTIONS]" } else { &req_opts[..] }
+ } else { "" },
+ if pos {
+ if req_pos. is_empty() { "[POSITIONAL]"} else { &req_pos[..] }
+ } else { ""},
+ if subcmds { "[SUBCOMMANDS]"} else { ""});
+ }
- if more_info {
- println!( "\nFor more information try --help");
- }
- }
+ if more_info {
+ println!( "\nFor more information try --help");
+ }
+ }
- fn print_help( &self) {
- self. print_version( false);
- let flags = ! self. flags. is_empty();
- let pos = ! self. positionals_idx. is_empty();
- let opts = ! self. opts. is_empty();
- let subcmds = ! self. subcommands. is_empty();
+ fn print_help( &self) {
+ self. print_version( false);
+ let flags = ! self. flags. is_empty();
+ let pos = ! self. positionals_idx. is_empty();
+ let opts = ! self. opts. is_empty();
+ let subcmds = ! self. subcommands. is_empty();
- if let Some( author) = self. author {
- println!( "{}", author);
- }
- if let Some( about) = self. about {
- println!( "{}", about);
- }
- println!( "");
- self. print_usage( false);
- if flags || opts || pos || subcmds {
- println!( "");
- }
- if flags {
- println!( "");
- println!( "FLAGS:");
- for v in self. flags. values() {
- println!( "\t{}{}\t{}",
- if let Some( s) = v. short{ format!( "-{}", s)} else{ format!( " ")},
- if let Some( l) = v. long { format!( ",--{}", l)} else { format!( " \t")},
- if let Some( h) = v. help { h} else { " "} );
- }
- }
- if opts {
- println!( "");
- println!( "OPTIONS:");
- for v in self. opts. values() {
- let mut needs_tab = false;
- println!( "\t{}{}{}\t{}",
- if let Some( ref s) = v. short{ format!( "-{} ", s)} else{ format!( " ")},
- if let Some( ref l) = v. long { format!( ",--{}=", l)} else { needs_tab = true; format!( " ")},
- format!( "{}", v. name. to_uppercase()),
- if let Some( ref h) = v. help { if needs_tab { format!( "\t{}", *h)} else { format!( "{}", *h) } } else { format!( " ")} );
- }
- }
- if pos {
- println!( "");
- println!( "POSITIONAL ARGUMENTS:");
- for v in self. positionals_idx. values() {
- println!( "\t{}\t\t\t{}", v. name,
- if let Some( h) = v. help { h} else { " "} );
- }
- }
- if subcmds {
- println!( "");
- println!( "SUBCOMMANDS:");
- for sc in self. subcommands. values() {
- println!( "\t{}\t\t{}", sc. name,
- if let Some( a) = sc. about { a} else { " "} );
- }
- }
+ if let Some( author) = self. author {
+ println!( "{}", author);
+ }
+ if let Some( about) = self. about {
+ println!( "{}", about);
+ }
+ println!( "");
+ self. print_usage( false);
+ if flags || opts || pos || subcmds {
+ println!( "");
+ }
+ if flags {
+ println!( "");
+ println!( "FLAGS:");
+ for v in self. flags. values() {
+ println!( "\t{}{}\t{}",
+ if let Some( s) = v. short{ format!( "-{}", s)} else{ format!( " ")},
+ if let Some( l) = v. long { format!( ",--{}", l)} else { format!( " \t")},
+ if let Some( h) = v. help { h} else { " "} );
+ }
+ }
+ if opts {
+ println!( "");
+ println!( "OPTIONS:");
+ for v in self. opts. values() {
+ let mut needs_tab = false;
+ println!( "\t{}{}{}\t{}",
+ if let Some( ref s) = v. short{ format!( "-{} ", s)} else{ format!( " ")},
+ if let Some( ref l) = v. long { format!( ",--{}=", l)} else { needs_tab = true; format!( " ")},
+ format!( "{}", v. name. to_uppercase()),
+ if let Some( ref h) = v. help { if needs_tab { format!( "\t{}", *h)} else { format!( "{}", *h) } } else { format!( " ")} );
+ }
+ }
+ if pos {
+ println!( "");
+ println!( "POSITIONAL ARGUMENTS:");
+ for v in self. positionals_idx. values() {
+ println!( "\t{}\t\t\t{}", v. name,
+ if let Some( h) = v. help { h} else { " "} );
+ }
+ }
+ if subcmds {
+ println!( "");
+ println!( "SUBCOMMANDS:");
+ for sc in self. subcommands. values() {
+ println!( "\t{}\t\t{}", sc. name,
+ if let Some( a) = sc. about { a} else { " "} );
+ }
+ }
- self. exit();
- }
+ self. exit();
+ }
- fn print_version( &self, quit: bool) {
- println!( "{} {}", self. name, if let Some( v) = self. version { v} else { ""} );
- if quit { self. exit(); }
- }
+ fn print_version( &self, quit: bool) {
+ println!( "{} {}", self. name, if let Some( v) = self. version { v} else { ""} );
+ if quit { self. exit(); }
+ }
- fn check_for_help_and_version( &self, arg: char) {
- if arg == 'h' && self. needs_short_help {
- self. print_help();
- } else if arg == 'v' && self. needs_short_version {
- self. print_version( true);
- }
- }
+ fn check_for_help_and_version( &self, arg: char) {
+ if arg == 'h' && self. needs_short_help {
+ self. print_help();
+ } else if arg == 'v' && self. needs_short_version {
+ self. print_version( true);
+ }
+ }
- fn parse_long_arg( &mut self, matches: &mut ArgMatches , full_arg: &String) -> Option<&'static str> {
- let mut arg = full_arg. as_slice(). trim_left_matches( |c| c == '-');
- let mut found = false;
+ fn parse_long_arg( &mut self, matches: &mut ArgMatches , full_arg: &String) -> Option<&'static str> {
+ let mut arg = full_arg. as_slice(). trim_left_matches( |c| c == '-');
+ let mut found = false;
- if arg == "help" && self. needs_long_help {
- self. print_help();
- } else if arg == "version" && self. needs_long_version {
- self. print_version( true);
- }
+ if arg == "help" && self. needs_long_help {
+ self. print_help();
+ } else if arg == "version" && self. needs_long_version {
+ self. print_version( true);
+ }
- let mut arg_val: Option<String> = None;
+ let mut arg_val: Option<String> = None;
- if arg. contains( "=") {
- let arg_vec: Vec<&str> = arg. split( "="). collect();
- arg = arg_vec[ 0];
- arg_val = Some( arg_vec[ 1]. to_string());
- }
+ if arg. contains( "=") {
+ let arg_vec: Vec<&str> = arg. split( "="). collect();
+ arg = arg_vec[ 0];
+ arg_val = Some( arg_vec[ 1]. to_string());
+ }
- for ( k, v) in self. opts. iter() {
- if let Some( ref l) = v. long {
- if *l == arg {
- if self. blacklist. contains( k) {
- self. report_error( format!( "The argument --{} is mutually exclusive with one or more other arguments", arg),
- true, true);
- }
- matches. opts. insert( k, OptArg{
- name: v. name,
- short: v. short,
- long: v. long,
- help: v. help,
- required: v. required,
- blacklist: None,
- requires: None,
- value: arg_val. clone()
- });
- match arg_val {
- None => { return Some( v. name); },
- _ => { return None; }
- }
- }
- }
- }
+ for ( k, v) in self. opts. iter() {
+ if let Some( ref l) = v. long {
+ if *l == arg {
+ if self. blacklist. contains( k) {
+ self. report_error( format!( "The argument --{} is mutually exclusive with one or more other arguments", arg),
+ true, true);
+ }
+ matches. opts. insert( k, OptArg{
+ name: v. name,
+ short: v. short,
+ long: v. long,
+ help: v. help,
+ required: v. required,
+ blacklist: None,
+ requires: None,
+ value: arg_val. clone()
+ });
+ match arg_val {
+ None => { return Some( v. name); },
+ _ => { return None; }
+ }
+ }
+ }
+ }
- for ( k, v) in self. flags. iter() {
- if let Some( ref l) = v. long {
- if *l != arg { continue; }
- found = true;
- let mut multi = false;
- if let Some( ref mut f) = matches. flags. get_mut( k) {
- f. occurrences = if f. multiple { f. occurrences + 1 } else { 1 };
- multi = true;
- }
- if ! multi {
- if self. blacklist. contains( k) {
- self. report_error( format!( "The argument --{} is mutually exclusive with one or more other arguments", arg),
- true, true);
- }
- matches. flags. insert( k, FlagArg{
- name: v. name,
- short: v. short,
- long: v. long,
- help: v. help,
- multiple: v. multiple,
- occurrences: v. occurrences,
- blacklist: None,
- requires: None
- });
- if self. required. contains( k) {
- self. required. remove( k);
- }
- if let Some( ref bl) = v. blacklist {
- if ! bl. is_empty() {
- for name in bl. iter() {
- self. blacklist. insert( name);
- }
- }
- }
- }
- if let Some( ref reqs) = v. requires {
- if ! reqs. is_empty() {
- for n in reqs. iter() {
- if matches. opts. contains_key( n) { continue; }
- if matches. flags. contains_key( n) { continue; }
- if matches. positionals. contains_key( n) { continue; }
- self. required. insert( n);
- }
- }
- }
- break;
- }
- }
+ for ( k, v) in self. flags. iter() {
+ if let Some( ref l) = v. long {
+ if *l != arg { continue; }
+ found = true;
+ let mut multi = false;
+ if let Some( ref mut f) = matches. flags. get_mut( k) {
+ f. occurrences = if f. multiple { f. occurrences + 1 } else { 1 };
+ multi = true;
+ }
+ if ! multi {
+ if self. blacklist. contains( k) {
+ self. report_error( format!( "The argument --{} is mutually exclusive with one or more other arguments", arg),
+ true, true);
+ }
+ matches. flags. insert( k, FlagArg{
+ name: v. name,
+ short: v. short,
+ long: v. long,
+ help: v. help,
+ multiple: v. multiple,
+ occurrences: v. occurrences,
+ blacklist: None,
+ requires: None
+ });
+ if self. required. contains( k) {
+ self. required. remove( k);
+ }
+ if let Some( ref bl) = v. blacklist {
+ if ! bl. is_empty() {
+ for name in bl. iter() {
+ self. blacklist. insert( name);
+ }
+ }
+ }
+ }
+ if let Some( ref reqs) = v. requires {
+ if ! reqs. is_empty() {
+ for n in reqs. iter() {
+ if matches. opts. contains_key( n) { continue; }
+ if matches. flags. contains_key( n) { continue; }
+ if matches. positionals. contains_key( n) { continue; }
+ self. required. insert( n);
+ }
+ }
+ }
+ break;
+ }
+ }
- if ! found {
- self. report_error(
- format!( "Argument --{} isn't valid", arg),
- true, true);
- }
- None
- }
+ if ! found {
+ self. report_error(
+ format!( "Argument --{} isn't valid", arg),
+ true, true);
+ }
+ None
+ }
- fn parse_short_arg( &mut self, matches: &mut ArgMatches , full_arg: &String) -> Option<&'static str> {
- let arg = full_arg. as_slice(). trim_left_matches( |c| c == '-');
- if arg. len() > 1 {
-
- for c in arg. chars() {
- self. check_for_help_and_version( c);
- if ! self. parse_single_short_flag( matches, c) {
- self. report_error(
- format!( "Argument -{} isn't valid", c),
- true, true);
- }
- }
- } else {
-
- let arg_c = arg. char_at( 0);
- self. check_for_help_and_version( arg_c);
+ fn parse_short_arg( &mut self, matches: &mut ArgMatches , full_arg: &String) -> Option<&'static str> {
+ let arg = full_arg. as_slice(). trim_left_matches( |c| c == '-');
+ if arg. len() > 1 {
+
+ for c in arg. chars() {
+ self. check_for_help_and_version( c);
+ if ! self. parse_single_short_flag( matches, c) {
+ self. report_error(
+ format!( "Argument -{} isn't valid", c),
+ true, true);
+ }
+ }
+ } else {
+
+ let arg_c = arg. char_at( 0);
+ self. check_for_help_and_version( arg_c);
- if ! self. parse_single_short_flag( matches, arg_c) {
- for ( k, v) in self. opts. iter() {
- if let Some( s) = v. short {
- if s == arg_c {
- return Some( k)
- }
- }
- }
+ if ! self. parse_single_short_flag( matches, arg_c) {
+ for ( k, v) in self. opts. iter() {
+ if let Some( s) = v. short {
+ if s == arg_c {
+ return Some( k)
+ }
+ }
+ }
- self. report_error(
- format!( "Argument -{} isn't valid", arg_c),
- true, true);
- }
+ self. report_error(
+ format!( "Argument -{} isn't valid", arg_c),
+ true, true);
+ }
- }
- None
- }
+ }
+ None
+ }
- fn parse_single_short_flag( &mut self, matches: &mut ArgMatches, arg: char) -> bool {
- for ( k, v) in self. flags. iter() {
- if let Some( s) = v. short {
- if s != arg { continue; }
+ fn parse_single_short_flag( &mut self, matches: &mut ArgMatches, arg: char) -> bool {
+ for ( k, v) in self. flags. iter() {
+ if let Some( s) = v. short {
+ if s != arg { continue; }
- if !matches. flags. contains_key( k) {
- if self. blacklist. contains( k) {
- self. report_error( format!( "The argument -{} is mutually exclusive with one or more other arguments", arg),
- false, true);
- }
- matches. flags. insert( k, FlagArg{
- name: v. name,
- short: v. short,
- long: v. long,
- help: v. help,
- multiple: v. multiple,
- occurrences: v. occurrences,
- blacklist: None,
- requires: None
- });
- if self. required. contains( k) {
- self. required. remove( k);
- }
- if let Some( ref reqs) = v. requires {
- if ! reqs. is_empty() {
- for n in reqs. iter() {
- if matches. opts. contains_key( n) { continue; }
- if matches. flags. contains_key( n) { continue; }
- if matches. positionals. contains_key( n) { continue; }
- self. required. insert( n);
- }
- }
- }
- if let Some( ref bl) = v. blacklist {
- if ! bl. is_empty() {
- for name in bl. iter() {
- self. blacklist. insert( name);
- }
- }
- }
- } else if matches. flags. get( k). unwrap(). multiple {
- matches. flags. get_mut( k). unwrap(). occurrences += 1
- }
+ if !matches. flags. contains_key( k) {
+ if self. blacklist. contains( k) {
+ self. report_error( format!( "The argument -{} is mutually exclusive with one or more other arguments", arg),
+ false, true);
+ }
+ matches. flags. insert( k, FlagArg{
+ name: v. name,
+ short: v. short,
+ long: v. long,
+ help: v. help,
+ multiple: v. multiple,
+ occurrences: v. occurrences,
+ blacklist: None,
+ requires: None
+ });
+ if self. required. contains( k) {
+ self. required. remove( k);
+ }
+ if let Some( ref reqs) = v. requires {
+ if ! reqs. is_empty() {
+ for n in reqs. iter() {
+ if matches. opts. contains_key( n) { continue; }
+ if matches. flags. contains_key( n) { continue; }
+ if matches. positionals. contains_key( n) { continue; }
+ self. required. insert( n);
+ }
+ }
+ }
+ if let Some( ref bl) = v. blacklist {
+ if ! bl. is_empty() {
+ for name in bl. iter() {
+ self. blacklist. insert( name);
+ }
+ }
+ }
+ } else if matches. flags. get( k). unwrap(). multiple {
+ matches. flags. get_mut( k). unwrap(). occurrences += 1
+ }
- return true;
- }
- }
- false
- }
+ return true;
+ }
+ }
+ false
+ }
- fn validate_blacklist( &self, matches: &ArgMatches) {
- if ! self. blacklist. is_empty() {
- for name in self. blacklist. iter() {
- for ( k, v) in matches. flags. iter() {
- if k == name {
- self. report_error( format!( "The argument {} is mutually exclusive with one or more other arguments",
- if let Some( s) = v. short {
- format!( "-{}", s)
- } else if let Some( l) = v. long {
- format!( "--{}", l)
- } else {
- format!( "\"{}\"", v. name)
- }),
- true, true);
- }
- }
- for ( k, v) in matches. opts. iter() {
- if k == name {
- self. report_error( format!( "The argument {} is mutually exclusive with one or more other arguments",
- if let Some( s) = v. short {
- format!( "-{}", s)
- } else if let Some( l) = v. long {
- format!( "--{}", l)
- } else {
- format!( "\"{}\"", v. name)
- }),
- true, true);
- }
- }
- for ( k, v) in matches. positionals. iter() {
- if k == name {
- self. report_error( format!( "The argument \"{}\" is mutually exclusive with one or more other arguments", v. name),
- false, true);
- }
- }
- }
- }
- }
+ fn validate_blacklist( &self, matches: &ArgMatches) {
+ if ! self. blacklist. is_empty() {
+ for name in self. blacklist. iter() {
+ for ( k, v) in matches. flags. iter() {
+ if k == name {
+ self. report_error( format!( "The argument {} is mutually exclusive with one or more other arguments",
+ if let Some( s) = v. short {
+ format!( "-{}", s)
+ } else if let Some( l) = v. long {
+ format!( "--{}", l)
+ } else {
+ format!( "\"{}\"", v. name)
+ }),
+ true, true);
+ }
+ }
+ for ( k, v) in matches. opts. iter() {
+ if k == name {
+ self. report_error( format!( "The argument {} is mutually exclusive with one or more other arguments",
+ if let Some( s) = v. short {
+ format!( "-{}", s)
+ } else if let Some( l) = v. long {
+ format!( "--{}", l)
+ } else {
+ format!( "\"{}\"", v. name)
+ }),
+ true, true);
+ }
+ }
+ for ( k, v) in matches. positionals. iter() {
+ if k == name {
+ self. report_error( format!( "The argument \"{}\" is mutually exclusive with one or more other arguments", v. name),
+ false, true);
+ }
+ }
+ }
+ }
+ }
- fn create_help_and_version( &mut self) {
- if self. needs_long_help {
- self. flags. insert( "clap_help", FlagArg{
- name: "clap_help",
- short: if self. needs_short_help { Some( 'h') } else { None },
- long: Some( "help"),
- help: Some( "Prints this message"),
- blacklist: None,
- multiple: false,
- requires: None,
- occurrences: 1
- });
- }
- if self. needs_long_version {
- self. flags. insert( "clap_version", FlagArg{
- name: "clap_version",
- short: if self. needs_short_help { Some( 'v') } else { None },
- long: Some( "version"),
- help: Some( "Prints version information"),
- blacklist: None,
- multiple: false,
- requires: None,
- occurrences: 1
- });
- }
- if self. needs_subcmd_help && ! self. subcommands. is_empty() {
- self. subcommands. insert( "help", Box:: new( App:: new( "help"). about( "Prints this message")));
- }
- }
+ fn create_help_and_version( &mut self) {
+ if self. needs_long_help {
+ self. flags. insert( "clap_help", FlagArg{
+ name: "clap_help",
+ short: if self. needs_short_help { Some( 'h') } else { None },
+ long: Some( "help"),
+ help: Some( "Prints this message"),
+ blacklist: None,
+ multiple: false,
+ requires: None,
+ occurrences: 1
+ });
+ }
+ if self. needs_long_version {
+ self. flags. insert( "clap_version", FlagArg{
+ name: "clap_version",
+ short: if self. needs_short_help { Some( 'v') } else { None },
+ long: Some( "version"),
+ help: Some( "Prints version information"),
+ blacklist: None,
+ multiple: false,
+ requires: None,
+ occurrences: 1
+ });
+ }
+ if self. needs_subcmd_help && ! self. subcommands. is_empty() {
+ self. subcommands. insert( "help", Box:: new( App:: new( "help"). about( "Prints this message")));
+ }
+ }
- fn get_matches_from( &mut self, matches: &mut ArgMatches, it: &mut IntoIter<String>) {
- self. create_help_and_version();
+ fn get_matches_from( &mut self, matches: &mut ArgMatches, it: &mut IntoIter<String>) {
+ self. create_help_and_version();
-
- let mut subcmd_name: Option<&'static str> = None;
- let mut needs_val_of: Option<&'static str> = None;
- let mut pos_counter = 1;
- while let Some( arg) = it. next() {
- let arg_slice = arg. as_slice();
- let mut skip = false;
- if let Some( nvo) = needs_val_of {
- if let Some( ref opt) = self. opts. get( nvo) {
- if self. blacklist. contains( opt. name) {
- self. report_error(
- format!( "The argument {} is mutually exclusive with one or more other arguments",
- if let Some( long) = opt. long {
- format!( "--{}", long)
- } else{
- format!( "-{}", opt. short. unwrap())
- }), true, true);
- }
- matches. opts. insert( nvo, OptArg{
- name: opt. name,
- short: opt. short,
- long: opt. long,
- help: opt. help,
- requires: None,
- blacklist: None,
- required: opt. required,
- value: Some( arg. clone())
- });
- if let Some( ref bl) = opt. blacklist {
- if ! bl. is_empty() {
- for name in bl. iter() {
- self. blacklist. insert( name);
- }
- }
- }
- if self. required. contains( opt. name) {
- self. required. remove( opt. name);
- }
- if let Some( ref reqs) = opt. requires {
- if ! reqs. is_empty() {
- for n in reqs. iter() {
- if matches. opts. contains_key( n) { continue; }
- if matches. flags. contains_key( n) { continue; }
- if matches. positionals. contains_key( n) { continue; }
- self. required. insert( n);
- }
- }
- }
- skip = true;
- }
- }
- if skip {
- needs_val_of = None;
- continue;
- }
- if arg_slice. starts_with( "--") {
-
- needs_val_of = self. parse_long_arg( matches, &arg);
+
+ let mut subcmd_name: Option<&'static str> = None;
+ let mut needs_val_of: Option<&'static str> = None;
+ let mut pos_counter = 1;
+ while let Some( arg) = it. next() {
+ let arg_slice = arg. as_slice();
+ let mut skip = false;
+ if let Some( nvo) = needs_val_of {
+ if let Some( ref opt) = self. opts. get( nvo) {
+ if self. blacklist. contains( opt. name) {
+ self. report_error(
+ format!( "The argument {} is mutually exclusive with one or more other arguments",
+ if let Some( long) = opt. long {
+ format!( "--{}", long)
+ } else{
+ format!( "-{}", opt. short. unwrap())
+ }), true, true);
+ }
+ matches. opts. insert( nvo, OptArg{
+ name: opt. name,
+ short: opt. short,
+ long: opt. long,
+ help: opt. help,
+ requires: None,
+ blacklist: None,
+ required: opt. required,
+ value: Some( arg. clone())
+ });
+ if let Some( ref bl) = opt. blacklist {
+ if ! bl. is_empty() {
+ for name in bl. iter() {
+ self. blacklist. insert( name);
+ }
+ }
+ }
+ if self. required. contains( opt. name) {
+ self. required. remove( opt. name);
+ }
+ if let Some( ref reqs) = opt. requires {
+ if ! reqs. is_empty() {
+ for n in reqs. iter() {
+ if matches. opts. contains_key( n) { continue; }
+ if matches. flags. contains_key( n) { continue; }
+ if matches. positionals. contains_key( n) { continue; }
+ self. required. insert( n);
+ }
+ }
+ }
+ skip = true;
+ }
+ }
+ if skip {
+ needs_val_of = None;
+ continue;
+ }
+ if arg_slice. starts_with( "--") {
+
+ needs_val_of = self. parse_long_arg( matches, &arg);
- } else if arg_slice. starts_with( "-") {
- needs_val_of = self. parse_short_arg( matches, &arg);
- } else {
-
- if let Some( sca) = self. subcommands. get( arg_slice) {
- if sca. name == "help" {
- self. print_help();
- }
- subcmd_name = Some( sca. name);
- break;
- }
+ } else if arg_slice. starts_with( "-") {
+ needs_val_of = self. parse_short_arg( matches, &arg);
+ } else {
+
+ if let Some( sca) = self. subcommands. get( arg_slice) {
+ if sca. name == "help" {
+ self. print_help();
+ }
+ subcmd_name = Some( sca. name);
+ break;
+ }
- if self. positionals_idx. is_empty() {
- self. report_error(
- format!( "Found positional argument {}, but {} doesn't accept any", arg, self. name),
- true, true);
- }
- if let Some( ref p) = self. positionals_idx. get( &pos_counter) {
- if self. blacklist. contains( p. name) {
- self. report_error( format!( "The argument \"{}\" is mutually exclusive with one or more other arguments", arg),
- true, true);
- }
- matches. positionals. insert( p. name, PosArg{
- name: p. name,
- help: p. help,
- required: p. required,
- blacklist: None,
- requires: None,
- value: Some( arg. clone()),
- index: pos_counter
- });
- if let Some( ref bl) = p. blacklist {
- if ! bl. is_empty() {
- for name in bl. iter() {
- self. blacklist. insert( name);
- }
- }
- }
- if self. required. contains( p. name) {
- self. required. remove( p. name);
- }
- if let Some( ref reqs) = p. requires {
- if ! reqs. is_empty() {
- for n in reqs. iter() {
- if matches. opts. contains_key( n) { continue; }
- if matches. flags. contains_key( n) { continue; }
- if matches. positionals. contains_key( n) { continue; }
- self. required. insert( n);
- }
- }
- }
- pos_counter += 1;
- } else {
- self. report_error( format!( "Positional argument \"{}\" was found, but {} wasn't expecting any", arg, self. name), true, true);
- }
- }
- }
+ if self. positionals_idx. is_empty() {
+ self. report_error(
+ format!( "Found positional argument {}, but {} doesn't accept any", arg, self. name),
+ true, true);
+ }
+ if let Some( ref p) = self. positionals_idx. get( &pos_counter) {
+ if self. blacklist. contains( p. name) {
+ self. report_error( format!( "The argument \"{}\" is mutually exclusive with one or more other arguments", arg),
+ true, true);
+ }
+ matches. positionals. insert( p. name, PosArg{
+ name: p. name,
+ help: p. help,
+ required: p. required,
+ blacklist: None,
+ requires: None,
+ value: Some( arg. clone()),
+ index: pos_counter
+ });
+ if let Some( ref bl) = p. blacklist {
+ if ! bl. is_empty() {
+ for name in bl. iter() {
+ self. blacklist. insert( name);
+ }
+ }
+ }
+ if self. required. contains( p. name) {
+ self. required. remove( p. name);
+ }
+ if let Some( ref reqs) = p. requires {
+ if ! reqs. is_empty() {
+ for n in reqs. iter() {
+ if matches. opts. contains_key( n) { continue; }
+ if matches. flags. contains_key( n) { continue; }
+ if matches. positionals. contains_key( n) { continue; }
+ self. required. insert( n);
+ }
+ }
+ }
+ pos_counter += 1;
+ } else {
+ self. report_error( format!( "Positional argument \"{}\" was found, but {} wasn't expecting any", arg, self. name), true, true);
+ }
+ }
+ }
- match needs_val_of {
- Some( ref a) => {
- self. report_error(
- format!( "Argument \"{}\" requires a value but none was supplied", a),
- true, true);
- }
- _ => {}
- }
- if ! self. required. is_empty() {
- self. report_error( "One or more required arguments were not supplied". to_string(),
- true, true);
- }
+ match needs_val_of {
+ Some( ref a) => {
+ self. report_error(
+ format!( "Argument \"{}\" requires a value but none was supplied", a),
+ true, true);
+ }
+ _ => {}
+ }
+ if ! self. required. is_empty() {
+ self. report_error( "One or more required arguments were not supplied". to_string(),
+ true, true);
+ }
- self. validate_blacklist( &matches);
+ self. validate_blacklist( &matches);
- if let Some( sc_name) = subcmd_name {
- if let Some( ref mut sc) = self. subcommands. get_mut( sc_name) {
- let mut new_matches = ArgMatches:: new( sc_name);
- sc. get_matches_from( &mut new_matches, it);
- matches. subcommand = Some(( sc_name, Box:: new( SubCommand{
- name: sc_name,
- matches: new_matches})));
- }
- }
- }
+ if let Some( sc_name) = subcmd_name {
+ if let Some( ref mut sc) = self. subcommands. get_mut( sc_name) {
+ let mut new_matches = ArgMatches:: new( sc_name);
+ sc. get_matches_from( &mut new_matches, it);
+ matches. subcommand = Some(( sc_name, Box:: new( SubCommand{
+ name: sc_name,
+ matches: new_matches})));
+ }
+ }
+ }
- pub fn get_matches( mut self) -> ArgMatches {
- let mut matches = ArgMatches:: new( self. name);
+ pub fn get_matches( mut self) -> ArgMatches {
+ let mut matches = ArgMatches:: new( self. name);
- let args = env:: args(). collect:: <Vec<_ >>();
- let mut it = args. into_iter();
- if let Some( name) = it. next() {
- let p = Path:: new( &name[..]);
- if let Some( f) = p. file_name() {
- match f. to_os_string(). into_string() {
- Ok( s) => self. bin_name = Some( s),
- Err(_) => {}
- }
- }
- }
- self. get_matches_from( &mut matches, &mut it );
+ let args = env:: args(). collect:: <Vec<_ >>();
+ let mut it = args. into_iter();
+ if let Some( name) = it. next() {
+ let p = Path:: new( &name[..]);
+ if let Some( f) = p. file_name() {
+ match f. to_os_string(). into_string() {
+ Ok( s) => self. bin_name = Some( s),
+ Err(_) => {}
+ }
+ }
+ }
+ self. get_matches_from( &mut matches, &mut it );
- matches
- }
+ matches
+ }
}
diff --git a/docs/src/clap/arg.rs/arg.rs.html b/docs/src/clap/arg.rs/arg.rs.html
index 0e48e089..48afd778 100644
--- a/docs/src/clap/arg.rs/arg.rs.html
+++ b/docs/src/clap/arg.rs/arg.rs.html
@@ -400,7 +400,7 @@
pub struct Arg {
-
+
pub name: &'static str,
@@ -427,295 +427,295 @@
pub multiple: bool,
- pub blacklist: Option<Vec<&'static str>>,
+ pub blacklist: Option<Vec<&'static str>>,
pub requires: Option<Vec<&'static str>>
}
impl Arg {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- pub fn new( n: &'static str) -> Arg {
- Arg {
- name: n,
- short: None,
- long: None,
- help: None,
- required: false,
- takes_value: false,
- multiple: false,
- index: None,
- blacklist: Some( vec![]),
- requires: Some( vec![]),
- }
- }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pub fn new( n: &'static str) -> Arg {
+ Arg {
+ name: n,
+ short: None,
+ long: None,
+ help: None,
+ required: false,
+ takes_value: false,
+ multiple: false,
+ index: None,
+ blacklist: Some( vec![]),
+ requires: Some( vec![]),
+ }
+ }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- pub fn short( mut self, s: &'static str) -> Arg {
- self. short = Some( s. trim_left_matches( |c| c == '-')
- . char_at( 0));
- self
- }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pub fn short( mut self, s: &'static str) -> Arg {
+ self. short = Some( s. trim_left_matches( |c| c == '-')
+ . char_at( 0));
+ self
+ }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- pub fn long( mut self, l: &'static str) -> Arg {
- self. long = Some( l. trim_left_matches( |c| c == '-'));
- self
- }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pub fn long( mut self, l: &'static str) -> Arg {
+ self. long = Some( l. trim_left_matches( |c| c == '-'));
+ self
+ }
-
-
-
-
-
-
-
-
-
-
-
-
- pub fn help( mut self, h: &'static str) -> Arg {
- self. help = Some( h);
- self
- }
+
+
+
+
+
+
+
+
+
+
+
+
+ pub fn help( mut self, h: &'static str) -> Arg {
+ self. help = Some( h);
+ self
+ }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- pub fn required( mut self, r: bool) -> Arg {
- self. required = r;
- self
- }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pub fn required( mut self, r: bool) -> Arg {
+ self. required = r;
+ self
+ }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- pub fn mutually_excludes( mut self, name: &'static str) -> Arg {
- if let Some( ref mut vec) = self. blacklist {
- vec. push( name);
- } else {
- self. blacklist = Some( vec![]);
- }
- self
- }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pub fn mutually_excludes( mut self, name: &'static str) -> Arg {
+ if let Some( ref mut vec) = self. blacklist {
+ vec. push( name);
+ } else {
+ self. blacklist = Some( vec![]);
+ }
+ self
+ }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- pub fn mutually_excludes_all( mut self, names: Vec<&'static str>) -> Arg {
- if let Some( ref mut vec) = self. blacklist {
- for n in names {
- vec. push( n);
- }
- } else {
- self. blacklist = Some( vec![]);
- }
- self
- }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pub fn mutually_excludes_all( mut self, names: Vec<&'static str>) -> Arg {
+ if let Some( ref mut vec) = self. blacklist {
+ for n in names {
+ vec. push( n);
+ }
+ } else {
+ self. blacklist = Some( vec![]);
+ }
+ self
+ }
-
-
-
-
-
-
-
-
-
-
-
-
- pub fn requires( mut self, name: &'static str) -> Arg {
- if let Some( ref mut vec) = self. requires {
- vec. push( name);
- } else {
- self. requires = Some( vec![]);
- }
- self
- }
+
+
+
+
+
+
+
+
+
+
+
+
+ pub fn requires( mut self, name: &'static str) -> Arg {
+ if let Some( ref mut vec) = self. requires {
+ vec. push( name);
+ } else {
+ self. requires = Some( vec![]);
+ }
+ self
+ }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- pub fn requires_all( mut self, names: Vec<&'static str>) -> Arg {
- if let Some( ref mut vec) = self. requires {
- for n in names {
- vec. push( n);
- }
- } else {
- self. requires = Some( vec![]);
- }
- self
- }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pub fn requires_all( mut self, names: Vec<&'static str>) -> Arg {
+ if let Some( ref mut vec) = self. requires {
+ for n in names {
+ vec. push( n);
+ }
+ } else {
+ self. requires = Some( vec![]);
+ }
+ self
+ }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- pub fn takes_value( mut self, tv: bool) -> Arg {
- assert!( self. index == None);
- self. takes_value = tv;
- self
- }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pub fn takes_value( mut self, tv: bool) -> Arg {
+ assert!( self. index == None);
+ self. takes_value = tv;
+ self
+ }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- pub fn index( mut self, idx: u8) -> Arg {
- assert!( self. takes_value == false);
- if idx < 1 { panic!( "Argument index must start at 1"); }
- self. index = Some( idx);
- self
- }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pub fn index( mut self, idx: u8) -> Arg {
+ assert!( self. takes_value == false);
+ if idx < 1 { panic!( "Argument index must start at 1"); }
+ self. index = Some( idx);
+ self
+ }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- pub fn multiple( mut self, multi: bool) -> Arg {
- assert!( self. takes_value == false);
- assert!( self. index == None);
- self. multiple = multi;
- self
- }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pub fn multiple( mut self, multi: bool) -> Arg {
+ assert!( self. takes_value == false);
+ assert!( self. index == None);
+ self. multiple = multi;
+ self
+ }
}
diff --git a/docs/src/clap/argmatches.rs/argmatches.rs.html b/docs/src/clap/argmatches.rs/argmatches.rs.html
index b7120321..98540824 100644
--- a/docs/src/clap/argmatches.rs/argmatches.rs.html
+++ b/docs/src/clap/argmatches.rs/argmatches.rs.html
@@ -325,15 +325,15 @@
- pub fn new( name: &'static str) -> ArgMatches {
- ArgMatches {
- matches_of: name,
+ pub fn new( name: &'static str) -> ArgMatches {
+ ArgMatches {
+ matches_of: name,
flags: HashMap:: new(),
opts: HashMap:: new(),
positionals: HashMap:: new(),
subcommand: None
- }
- }
+ }
+ }
@@ -348,19 +348,19 @@
- pub fn value_of( &self, name: &'static str) -> Option<&String> {
+ pub fn value_of( &self, name: &'static str) -> Option<&String> {
if let Some( ref opt) = self. opts. get( name) {
- if let Some( ref v) = opt. value {
- return Some( v);
- }
+ if let Some( ref v) = opt. value {
+ return Some( v);
+ }
}
if let Some( ref pos) = self. positionals. get( name) {
- if let Some( ref v) = pos. value {
- return Some( v);
- }
+ if let Some( ref v) = pos. value {
+ return Some( v);
+ }
}
None
- }
+ }
@@ -375,7 +375,7 @@
- pub fn is_present( &self, name: &'static str) -> bool {
+ pub fn is_present( &self, name: &'static str) -> bool {
if let Some(( sc_name, _ )) = self. subcommand {
if sc_name == name { return true; }
}
@@ -385,7 +385,7 @@
return true;
}
false
- }
+ }
diff --git a/docs/src/clap/lib.rs/lib.rs.html b/docs/src/clap/lib.rs/lib.rs.html
index 58df1bb0..9e1963a6 100644
--- a/docs/src/clap/lib.rs/lib.rs.html
+++ b/docs/src/clap/lib.rs/lib.rs.html
@@ -220,50 +220,50 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
@@ -277,22 +277,22 @@
-
+
-
-
-
+
+
+
-
+
-
+
-
-
+
+
pub use argmatches:: ArgMatches;
@@ -310,46 +310,46 @@
mod tests {
use super:: *;
- #[test]
- #[should_panic]
- fn unique_arg_names(){
- App:: new( "some"). args( vec![
- Arg:: new( "arg"). short( "a"),
- Arg:: new( "arg"). short( "b")
- ]);
- }
- #[test]
- #[should_panic]
- fn unique_arg_shorts(){
- App:: new( "some"). args( vec![
- Arg:: new( "arg1"). short( "a"),
- Arg:: new( "arg2"). short( "a")
- ]);
- }
- #[test]
- #[should_panic]
- fn unique_arg_longs(){
- App:: new( "some"). args( vec![
- Arg:: new( "arg1"). long( "long"),
- Arg:: new( "arg2"). long( "long")
- ]);
- }
- #[test]
- fn create_app(){
- App:: new( "some"). about( "about"). author( "author"). version( "1.0");
- }
- #[test]
- fn create_arg_flag(){
- Arg:: new( "some"). short( "a"). long( "long"). help( "help with some arg"). multiple( true);
- }
- #[test]
- fn create_arg_pos(){
- Arg:: new( "some"). index( 1). help( "help with some arg"). required( true);
- }
- #[test]
- fn create_arg_opt(){
- Arg:: new( "some"). short( "s"). long( "some"). takes_value( true). help( "help with some arg"). required( true);
- }
+ #[test]
+ #[should_panic]
+ fn unique_arg_names(){
+ App:: new( "some"). args( vec![
+ Arg:: new( "arg"). short( "a"),
+ Arg:: new( "arg"). short( "b")
+ ]);
+ }
+ #[test]
+ #[should_panic]
+ fn unique_arg_shorts(){
+ App:: new( "some"). args( vec![
+ Arg:: new( "arg1"). short( "a"),
+ Arg:: new( "arg2"). short( "a")
+ ]);
+ }
+ #[test]
+ #[should_panic]
+ fn unique_arg_longs(){
+ App:: new( "some"). args( vec![
+ Arg:: new( "arg1"). long( "long"),
+ Arg:: new( "arg2"). long( "long")
+ ]);
+ }
+ #[test]
+ fn create_app(){
+ App:: new( "some"). about( "about"). author( "author"). version( "1.0");
+ }
+ #[test]
+ fn create_arg_flag(){
+ Arg:: new( "some"). short( "a"). long( "long"). help( "help with some arg"). multiple( true);
+ }
+ #[test]
+ fn create_arg_pos(){
+ Arg:: new( "some"). index( 1). help( "help with some arg"). required( true);
+ }
+ #[test]
+ fn create_arg_opt(){
+ Arg:: new( "some"). short( "s"). long( "some"). takes_value( true). help( "help with some arg"). required( true);
+ }
}
diff --git a/docs/src/clap/subcommand.rs/subcommand.rs.html b/docs/src/clap/subcommand.rs/subcommand.rs.html
index 66b3ade3..24316236 100644
--- a/docs/src/clap/subcommand.rs/subcommand.rs.html
+++ b/docs/src/clap/subcommand.rs/subcommand.rs.html
@@ -101,31 +101,31 @@
-
-
-
-
+
+
+
+
pub struct SubCommand {
- pub name: &'static str,
- pub matches: ArgMatches
+ pub name: &'static str,
+ pub matches: ArgMatches
}
impl SubCommand {
-
-
-
-
-
-
-
-
-
-
-
- pub fn new( name: &'static str) -> App {
- App:: new( name)
- }
+
+
+
+
+
+
+
+
+
+
+
+ pub fn new( name: &'static str) -> App {
+ App:: new( name)
+ }
}
|