81 lines
1.9 KiB
Rust
81 lines
1.9 KiB
Rust
use anyhow::Result;
|
|
use clap::{ArgAction, Parser};
|
|
|
|
mod posix;
|
|
mod sysv;
|
|
|
|
#[derive(Debug, Parser)]
|
|
enum Backend {
|
|
/// Handle POSIX message queues
|
|
#[clap(subcommand)]
|
|
Posix(PosixCommand),
|
|
/// Handle SysV message queues
|
|
#[clap(subcommand)]
|
|
Sysv(SysvCommand),
|
|
}
|
|
|
|
#[derive(Debug, Parser)]
|
|
enum PosixCommand {
|
|
Create(posix::Create),
|
|
Info(posix::Info),
|
|
List(posix::List),
|
|
Unlink(posix::Unlink),
|
|
Send(posix::Send),
|
|
Recv(posix::Recv),
|
|
}
|
|
|
|
#[derive(Debug, Parser)]
|
|
enum SysvCommand {
|
|
Create(sysv::Create),
|
|
Info(sysv::Info),
|
|
List(sysv::List),
|
|
Unlink(sysv::Unlink),
|
|
}
|
|
|
|
#[derive(Debug, Parser)]
|
|
#[clap(
|
|
arg_required_else_help = true,
|
|
infer_subcommands = true,
|
|
subcommand_required = true
|
|
)]
|
|
struct Opts {
|
|
/// Produce verbose output, multiple -v options increase the verbosity (max. 3)
|
|
#[clap(short, long, global = true, action = ArgAction::Count)]
|
|
verbose: u32,
|
|
/// Backend to be used
|
|
#[clap(subcommand)]
|
|
backend: Backend,
|
|
}
|
|
|
|
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.backend {
|
|
Backend::Posix(p) => match p {
|
|
PosixCommand::Create(c) => c.run()?,
|
|
PosixCommand::Info(i) => i.run()?,
|
|
PosixCommand::List(l) => l.run()?,
|
|
PosixCommand::Unlink(u) => u.run()?,
|
|
PosixCommand::Send(s) => s.run()?,
|
|
PosixCommand::Recv(r) => r.run()?,
|
|
},
|
|
Backend::Sysv(s) => match s {
|
|
SysvCommand::Create(c) => c.run()?,
|
|
SysvCommand::Info(i) => i.run()?,
|
|
SysvCommand::List(l) => l.run()?,
|
|
SysvCommand::Unlink(u) => u.run()?,
|
|
},
|
|
}
|
|
|
|
Ok(())
|
|
}
|