Macro quicli::main
[−]
[src]
macro_rules! main { (|$args:ident: $cli:ty, log_level: $verbosity:ident| $body:expr) => { ... }; (|$args:ident: $cli:ty| $body:expr) => { ... }; (|| $body:expr) => { ... }; ($body:expr) => { ... }; }
Quickly get a good main
function
Inside the block, you can write code using ?
. An Ok(())
will
automatically be appended.
Parameters
You can optionally call this macro with a closure-like syntax to get some default bindings:
main!(|args: Cli| { ... })
: Automatically parses command line flags into a structCli
and binds it toargs
. (Basically, it prependslet args = Cli::from_args();
).main!(|args: Cli, log_level: verbosity| { ... })
: In addition to parsing the command line flags intoargs
of typeCli
, it will also initialize a logger.The log level will depend on the integer value of the
verbosity
field ofargs
(error = 0, warn = 1, info = 2, debug = 3, trace = ≥4). The field's type should beu64
, so structopt will automatically give you its number of occurances.
Examples
⚠Be careful when using this code, it's not being tested!
#[macro_use] extern crate quicli; use quicli::prelude::*; main!({ let x = read_file(".gitignore")?; println!("{}", x); });