Struct clap::App
[−]
[src]
pub struct App<'a, 'v, 'ab, 'u, 'ar> { // some fields omitted }
Used to create a representation of the program and all possible command line arguments for parsing at runtime.
Stores a list of all posisble arguments, as well as information displayed to the user such as help and versioning information.
Example
let myprog = App::new("myprog") .author("Me, me@mail.com") .version("1.0.2") .about("Explains in brief what the program does") .arg( Arg::new("in_file").index(1) // Add other possible command line argument options here... ) .get_matches(); // Your pogram logic starts here...
Methods
impl<'a, 'v, 'ab, 'u, 'ar> App<'a, 'v, 'ab, 'u, 'ar>
[src]
fn new<'n>(n: &'n str) -> App<'a, 'v, 'ab, 'u, 'ar>
Creates a new instance of an application requiring a name (such as the binary). Will be displayed to the user when they print version or help and usage information.
Example
let prog = App::new("myprog")
fn author(self, a: &'a str) -> App<'a, 'v, 'ab, 'u, 'ar>
fn about(self, a: &'ab str) -> App<'a, 'v, 'ab, 'u, 'ar>
Sets a string briefly describing what the program does
Example
.about("Does really amazing things to great people")
fn version(self, v: &'v str) -> App<'a, 'v, 'ab, 'u, 'ar>
fn usage(self, u: &'u str) -> App<'a, 'v, 'ab, 'u, 'ar>
Sets a custom usage string to over-ride the one auto-generated by clap
NOTE: You do not need to specify the "USAGE: " 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.
Example
.usage("myapp [-clDas] <some_file>")
fn arg<'l, 'h, 'b, 'r>(self, a: Arg<'ar, 'ar, 'ar, 'ar, 'ar, 'ar>) -> App<'a, 'v, 'ab, 'u, 'ar>
Adds an argument to the list of valid possibilties
Example
.arg(Arg::new("config") .short("c") // Additional argument configuration goes here... )
fn args(self, args: Vec<Arg<'ar, 'ar, 'ar, 'ar, 'ar, 'ar>>) -> App<'a, 'v, 'ab, 'u, 'ar>
Adds multiple arguments to the list of valid possibilties
Example
.args( vec![Arg::new("config").short("c"), Arg::new("debug").short("d")])
fn subcommand(self, subcmd: App<'a, 'v, 'ab, 'u, 'ar>) -> App<'a, 'v, 'ab, 'u, 'ar>
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.
Example
.subcommand(SubCommand::new("config") .about("Controls configuration features") .arg(Arg::new("config_file") .index(1) .help("Configuration file to use"))) // Additional subcommand configuration goes here, such as arguments...
fn subcommands(self, subcmds: Vec<App<'a, 'v, 'ab, 'u, 'ar>>) -> App<'a, 'v, 'ab, 'u, 'ar>
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")])