pub struct Clappers { /* private fields */ }

Implementations

Build a Clappers parser

Parameters

None.

Return value

An empty Clappers parser, which is ready to be configured by chaining:

  • set_flags()
  • set_singles()
  • set_multiples()

Once configured, parse() is chained last to parse the actual command line arguments

Example
use clappers::Clappers;

fn main() {
    let clappers = Clappers::build()
        .set_flags(vec!["h|help", "v|verbose"])
        .set_singles(vec!["o|output", "u|username"])
        .set_multiples(vec!["i|input", "host"])
        .parse();

    // ...
}

Add flag argument parsing to the Clappers config

Flag arguments are true if they were supplied on the command line, and false otherwise e.g:

 -h
 --help
 -v
 --verbose

Note: flag arguments do not take values

Parameters

arg_specs specifies which flag arguments on the command line to care about.

Each arg_spec contains “|” separated flag argument alias names e.g:

 clappers.set_flags(vec!["h|help", "v|verbose"]);
Return value

The Clappers parser so that it can be chained

Example
use clappers::Clappers;

fn main() {
    let clappers = Clappers::build()
        .set_flags(vec!["h|help", "v|verbose"])
        .set_singles(vec!["o|output", "u|username"])
        .set_multiples(vec!["i|input", "host"])
        .parse();

    // ...
}

Add single value argument parsing to the Clappers config

Single value arguments contain a single String value if they were supplied on the command line, and empty String otherwise e.g:

 -o filename.txt
 --output filename.txt
 -u Zelensky
 --username Zelensky
Parameters

arg_specs specifies which single value arguments on the command line to care about.

Each arg_spec contains “|” separated single value argument alias names e.g:

 clappers.set_singles(vec!["o|output", "u|username"]);
Return value

The Clappers parser so that it can be chained

Example
use clappers::Clappers;

fn main() {
    let clappers = Clappers::build()
        .set_flags(vec!["h|help", "v|verbose"])
        .set_singles(vec!["o|output", "u|username"])
        .set_multiples(vec!["i|input", "host"])
        .parse();

    // ...
}

Add multiple value argument parsing to the Clappers config

Multiple value arguments contain at least a singly populated Vec<String> value if they were supplied on the command line, and empty Vec<String> otherwise e.g:

 -i file1.txt
 --input file1.txt
 --host host1

They can also contain multiple values, by repetition on the command line e.g:

 -i file1.txt -i file2.txt ... -i fileN.txt
 --host host1 --host host2 ... --host hostN

The following format also works, reading from the first value until either the next argument is reached, or until the end of the entire command line arguments e.g:

 -i file1.txt file2.txt ... fileN.txt -n next_argument
 --host host1 host2 hostN
Parameters

arg_specs specifies which multiple value arguments on the command line to care about.

Each arg_spec contains “|” separated multiple value argument alias names e.g:

 clappers.set_multiples(vec!["i|input", "host"]);
Return value

The Clappers parser so that it can be chained

Example
use clappers::Clappers;

fn main() {
    let clappers = Clappers::build()
        .set_flags(vec!["h|help", "v|verbose"])
        .set_singles(vec!["o|output", "u|username"])
        .set_multiples(vec!["i|input", "host"])
        .parse();

    // ...
}

Parse the command line arguments with the current Clappers config

Parameters

None

Return value

The Clappers parser containing the parsed command line arguments values, accessed with:

  • get_flags()
  • get_singles()
  • get_multiples()
  • get_leftovers()
Example
use clappers::Clappers;

fn main() {
    let clappers = Clappers::build()
        .set_flags(vec!["h|help", "v|verbose"])
        .set_singles(vec!["o|output", "u|username"])
        .set_multiples(vec!["i|input", "host"])
        .parse();

    if clappers.get_flag("help") {
        // Show help text
    }

    // ...
}

Check if the flag was supplied on the command line for the specified argument

Parameters

argument is any alias of the specified argument

Return value

true if the flag was supplied on the command line, and false otherwise

Example
use clappers::Clappers;

fn main() {
    let clappers = Clappers::build()
        .set_flags(vec!["h|help"])
        .parse();

    if clappers.get_flag("help") {
        // Show help text
    }

    if clappers.get_flag("h") {
        // This will also show the help text
    }

    // ...
}

Get the single value supplied on the command line for the specified argument

Parameters

argument is any alias of the specified argument

Return value

The single String value if they were supplied on the command line, and empty String otherwise

Example
use clappers::Clappers;

fn main() {
    let clappers = Clappers::build()
        .set_singles(vec!["output"])
        .parse();

    println!("Output filename is {}", clappers.get_single("output"));

    // ...
}

Get multiple values supplied on the command line for the specified argument

Parameters

argument is any alias of the specified argument

Return value

Multiple String values if they were supplied on the command line, and empty Vec<String> otherwise

Example
use clappers::Clappers;

fn main() {
    let clappers = Clappers::build()
        .set_multiples(vec!["input"])
        .parse();

    println!("Input filenames are {:#?}", clappers.get_multiple("input"));

    // ...
}

Get all values supplied on the command line that are not associated with any argument

Parameters

None

Return value

All String values supplied on the command line that are not associated with any argument, and empty Vec<String> otherwise

Example
use clappers::Clappers;

fn main() {
    let clappers = Clappers::build()
        .parse();

    println!("`ls *` returned the following filenames: {:#?}", clappers.get_leftovers());

    // ...
}

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.