Skip to content

Instantly share code, notes, and snippets.

@cardoe
Created September 5, 2017 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cardoe/06de06f29ea2133d611e157b4ca161fc to your computer and use it in GitHub Desktop.
Save cardoe/06de06f29ea2133d611e157b4ca161fc to your computer and use it in GitHub Desktop.
clap example operating the way a user commented on reddit
#[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