Struct kripher::options::Options [] [src]

pub struct Options {
    pub version: bool,
    pub encode: bool,
    pub decode: bool,
    pub output: Option<String>,
    pub rest: Vec<String>,
}

Stores the options so our programs knows what to do.

Normaly you obtain this struct as a result of parsing the command line arguments passed to the program.

In this program we have only three different flags that can be activated. We store this information with three bools. The remaining command line arguments after the parsing are stored in a new Vec<String> named Options::rest.

Fields

Whether the --version flag was activated or not.

Whether the --encode flag was activated or not.

Whether the --decode flag was activated or not.

If the --output option was set, here is the program's output filename stored. Otherwise None.

The remaining command line arguments that weren't parsed.

Methods

impl Options
[src]

Takes a vector of String and creates a Options struct.

Usually you want to parse std::env::args() to detect when the different command line flags were activated. Note that normally the first element to appear in std::env::args() is the executable name, so you should skip it.

Examples

use kripher::options::Options;
use std::env;

let args = env::args().skip(1);
let o = Options::from_args(args);

if o.version {
    println!("The --version flag was active.")
}