Crate structopt_flags[][src]

structopt-flags is a collection of reusable CLI flags and options based on structopt

Every flag or option is already pre-configured and can be used marking the field as flatten

Currently, a set of verbosity flags and log level option are provided. Some flags and options are provided in multiple configuration, to leave the choice to the developer which one to use. For instance, there are 4 type for vebosity flag:

  • Verbose: -v flag, it provides a log level with Error as default level
  • QuietVerbose: -v flag to increase vebosity, -q to decrease it; default level: Warning
  • SimpleVebose: -v flag as boolean, no default log level provided
  • VeboseNoDef: -v flag, to increase verbosity, but without a default value

Example

extern crate structopt_flags;
#[macro_use]
extern crate structopt;

use structopt::StructOpt;
use structopt_flags::LogLevel; // to access get_log_level

#[derive(Debug, StructOpt)]
#[structopt(name = "verbose", about = "An example using verbose flag")]
struct Opt {
    #[structopt(flatten)]
    verbose: structopt_flags::Verbose,
}

fn main() {
    let opt = Opt::from_args();
    let log_level_filter = opt.verbose.get_level_filter();
}

Structs

HostOpt

This struct provides the --host and -H cli option to get ageneric IP address

HostV4Opt

This struct provides the --host and -H cli option to get an IPv4 address

HostV6Opt

This struct provides the --host and -H cli option to get an IPv6 address

LogLevelNoDef

This struct provides the --log and -L cli option, with no default

LogLevelNoDefLower

This struct provides the --log and -l cli option, with no default

LogLevelOpt

This struct provides the --log and -L cli option

LogLevelOptLower

This struct provides the --log and -l cli option

QuietVerbose

This struct implements the --verbose and the --quiet cli options

SimpleVerbose

This struct implements the --verbose cli option as a boolean flag

Verbose

This struct provides the --verbose cli option

VerboseNoDef

This struct provides the --verbose cli option, without a predefined default

Enums

Level

An enum representing the available verbosity levels of the logger.

LevelFilter

An enum representing the available verbosity level filters of the logger.

Traits

GetWithDefault

This trait is designed to provide a rude form of default value for options If an option doesn't have a default value, it will implement this trait

LogLevel

This trait is designed to provide a log level compatible with the Log crates Options or flags that can provide a log level, will implement this trait