#log #structopt #flags #cli #clap

clap-log-flag

Add a logger to CLIs using structopt

3 unstable releases

Uses old Rust 2015

0.2.1 Aug 22, 2018
0.2.0 Aug 22, 2018
0.1.0 Aug 6, 2018

#13 in #structopt

Download history 1/week @ 2024-11-13 5/week @ 2024-11-20 10/week @ 2024-11-27 10/week @ 2024-12-04 23/week @ 2024-12-11 8/week @ 2024-12-18 9/week @ 2025-01-08 10/week @ 2025-01-15 4/week @ 2025-01-22 4/week @ 2025-01-29 78/week @ 2025-02-05 39/week @ 2025-02-12 27/week @ 2025-02-26

145 downloads per month
Used in 3 crates (via nest-cli)

MIT/Apache

11KB
53 lines

clap-log-flag

crates.io version build status downloads docs.rs docs

Add a logger to CLIs using structopt.

Usage

extern crate clap_log_flag;
#[macro_use]
extern crate log;
extern crate clap_verbosity_flag;
#[macro_use]
extern crate structopt;

use structopt::StructOpt;

#[derive(Debug, StructOpt)]
struct Cli {
  #[structopt(flatten)]
  verbose: clap_verbosity_flag::Verbosity,
  #[structopt(flatten)]
  log: clap_log_flag::Log,
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
  let args = Cli::from_args();
  args.log.log_all(args.verbose.log_level())?;
  info!("hello");
  error!("oh no!");
  Ok(())
}

Output

clap-log-flag 0.1.0
Yoshua Wuyts <yoshuawuyts@gmail.com>
Add a logger to CLIs using structopt

USAGE:
    main [FLAGS]

FLAGS:
    -h, --help         Prints help information
    -P, --pretty       Enable pretty printing.
    -V, --version      Prints version information
    -v, --verbosity    Pass many times for more log output

Installation

$ cargo add clap-log-flag

License

MIT OR Apache-2.0

Dependencies

~7–15MB
~191K SLoC