mqrs/src/main.rs
finga 12b117db7e Refactor logging
To supporte more than a single log level `log` and `env_logger` crates
are used. For the application to support the different type of
argument, the verbose argument definition was adapted.
2021-07-07 17:13:08 +02:00

54 lines
1.3 KiB
Rust

use anyhow::Result;
use clap::{crate_authors, crate_version, AppSettings, Clap};
mod posix;
#[derive(Clap, Debug)]
enum Command {
Create(posix::Create),
Info(posix::Info),
Unlink(posix::Unlink),
Send(posix::Send),
Recv(posix::Recv),
}
#[derive(Clap, Debug)]
#[clap(
version = crate_version!(),
author = crate_authors!(", "),
setting = AppSettings::SubcommandRequiredElseHelp,
global_setting = AppSettings::VersionlessSubcommands,
global_setting = AppSettings::InferSubcommands,
)]
struct Opts {
/// Produce verbose output, multiple -v options increase the verbosity (max. 3)
#[clap(short, long, global = true, parse(from_occurrences))]
verbose: u32,
#[clap(subcommand)]
command: Command,
}
fn main() -> Result<()> {
let opts: Opts = Opts::parse();
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or(
match opts.verbose {
0 => "warn",
1 => "info",
2 => "debug",
_ => "trace",
},
))
.init();
match opts.command {
Command::Create(c) => c.run()?,
Command::Info(i) => i.run()?,
Command::Unlink(u) => u.run()?,
Command::Send(s) => s.run()?,
Command::Recv(r) => r.run()?,
}
Ok(())
}