56 lines
1.3 KiB
Rust
56 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),
|
|
List(posix::List),
|
|
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()?,
|
|
Command::List(l) => l.run()?,
|
|
}
|
|
|
|
Ok(())
|
|
}
|