[][src]Crate entrance

Utilities for parsing command line arguments

entrance provides type assisted tools for parsing command line argumuments.

Usage

use entrance::*;
use std::path::PathBuf;

#[derive(Options)]
struct Opts {
    #[description = "Print help message"]
    #[short = 'h']
    help: bool,

    #[description = "Use verbose output"]
    #[short = 'v']
    verbose: bool,

    #[description = "Print version information"]
    version: bool,
}

#[derive(Arguments)]
struct Args {
    #[description = "Path to a file"]
    path: PathBuf,
}

let args = ["program", "-v", "path/to/file"].iter().map(|s| s.to_string());

// Parse only options to exit immediately with "--version" or "--help".
let command = Command::<Opts, Args>::new("program").parse_options(args).unwrap();

if command.options().version {
    // Print version information and exit.
}

if command.options().help {
    println!("{}", command.help());
    // Exit
}

// Parse the other arguments
let command = command.parse_arguments().unwrap();

assert!(!command.options().help);
assert!(!command.options().version);
assert!(command.options().verbose);

assert_eq!(command.arguments().path, PathBuf::from("path/to/file"));

Structs

Arg
Command

A struct containing parsed options and arguments.

CommandPrecursor

Helper struct for parsing command line arguments and returning Command.

HelpDisplay

Helper struct for printing help messages with format! and {}.

Opt
OptionParsedCommand

A struct as an intermediate just after parsing options.

Enums

ArgumentError
OptionError
OptionItem

Traits

Arguments

A trait for parsing and containing arguments.

Options

A trait for parsing and containing options.

Type Definitions

Result