Created
September 5, 2017 16:56
-
-
Save cardoe/06de06f29ea2133d611e157b4ca161fc to your computer and use it in GitHub Desktop.
clap example operating the way a user commented on reddit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[macro_use] | |
extern crate clap; | |
#[macro_use] | |
extern crate log; | |
extern crate stderrlog; | |
use clap::{Arg, App}; | |
fn main() { | |
let m = App::new("stderrlog example") | |
.version(crate_version!()) | |
.arg(Arg::with_name("verbosity") | |
.short("v") | |
.multiple(true) | |
.help("Increase message verbosity")) | |
.arg(Arg::with_name("quiet") | |
.short("q") | |
.multiple(true) | |
.help("opposite of verbosity")) | |
.arg(Arg::with_name("silence") | |
.short("s") | |
.help("Silence all output")) | |
.get_matches(); | |
let verbose = m.occurrences_of("verbosity") as usize; | |
let quiet = m.occurrences_of("quiet") as usize; | |
let silence = m.is_present("silence"); | |
stderrlog::new() | |
.module(module_path!()) | |
.quiet(silence) | |
.verbosity(verbose - quiet) | |
.init() | |
.unwrap(); | |
trace!("trace message"); | |
debug!("debug message"); | |
info!("info message"); | |
warn!("warn message"); | |
error!("error message"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment