[go: up one dir, main page]

Struct clap::App

source ·
pub struct App<'a, 'v, 'ab, 'u, 'ar> { /* private fields */ }
Expand description

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...

Implementations§

source§

impl<'a, 'v, 'ab, 'u, 'ar> App<'a, 'v, 'ab, 'u, 'ar>

source

pub 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")
source

pub fn author(self, a: &'a str) -> App<'a, 'v, 'ab, 'u, 'ar>

Sets a string of author(s)

§Example
.author("Kevin <kbknapp@gmail.com>")
source

pub 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")
source

pub fn version(self, v: &'v str) -> App<'a, 'v, 'ab, 'u, 'ar>

Sets a string of the version number

§Example
.version("v0.1.24")
source

pub 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>")
source

pub 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...
)
source

pub 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")])
source

pub 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...
source

pub 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")])
source

pub fn get_matches(self) -> ArgMatches<'ar>

Auto Trait Implementations§

§

impl<'a, 'v, 'ab, 'u, 'ar> Freeze for App<'a, 'v, 'ab, 'u, 'ar>

§

impl<'a, 'v, 'ab, 'u, 'ar> RefUnwindSafe for App<'a, 'v, 'ab, 'u, 'ar>

§

impl<'a, 'v, 'ab, 'u, 'ar> Send for App<'a, 'v, 'ab, 'u, 'ar>

§

impl<'a, 'v, 'ab, 'u, 'ar> Sync for App<'a, 'v, 'ab, 'u, 'ar>

§

impl<'a, 'v, 'ab, 'u, 'ar> Unpin for App<'a, 'v, 'ab, 'u, 'ar>

§

impl<'a, 'v, 'ab, 'u, 'ar> UnwindSafe for App<'a, 'v, 'ab, 'u, 'ar>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.