2021-06-14 03:06:23 +02:00
|
|
|
use anyhow::Result;
|
2021-12-03 14:50:23 +01:00
|
|
|
use clap::{crate_authors, crate_version, AppSettings, Parser};
|
2021-06-12 16:26:48 +02:00
|
|
|
|
2021-06-30 22:46:33 +02:00
|
|
|
mod posix;
|
2021-07-07 20:23:04 +02:00
|
|
|
mod sysv;
|
2021-06-30 22:46:33 +02:00
|
|
|
|
2021-12-03 14:50:23 +01:00
|
|
|
#[derive(Debug, Parser)]
|
2021-07-07 19:19:19 +02:00
|
|
|
enum Backend {
|
|
|
|
/// Handle POSIX message queues
|
2021-10-10 01:23:17 +02:00
|
|
|
#[clap(subcommand)]
|
2021-07-07 19:19:19 +02:00
|
|
|
Posix(PosixCommand),
|
|
|
|
/// Handle SysV message queues
|
2021-10-10 01:23:17 +02:00
|
|
|
#[clap(subcommand)]
|
2021-07-07 19:19:19 +02:00
|
|
|
Sysv(SysvCommand),
|
|
|
|
}
|
|
|
|
|
2021-12-03 14:50:23 +01:00
|
|
|
#[derive(Debug, Parser)]
|
2021-07-07 19:19:19 +02:00
|
|
|
enum PosixCommand {
|
2021-06-30 22:46:33 +02:00
|
|
|
Create(posix::Create),
|
|
|
|
Info(posix::Info),
|
2021-07-07 18:27:41 +02:00
|
|
|
List(posix::List),
|
2021-06-30 22:46:33 +02:00
|
|
|
Unlink(posix::Unlink),
|
|
|
|
Send(posix::Send),
|
|
|
|
Recv(posix::Recv),
|
|
|
|
}
|
2021-06-12 16:26:48 +02:00
|
|
|
|
2021-12-03 14:50:23 +01:00
|
|
|
#[derive(Debug, Parser)]
|
2021-07-07 19:19:19 +02:00
|
|
|
enum SysvCommand {
|
2021-07-07 20:23:04 +02:00
|
|
|
Create(sysv::Create),
|
2021-07-08 17:44:46 +02:00
|
|
|
Info(sysv::Info),
|
2021-07-08 14:46:10 +02:00
|
|
|
List(sysv::List),
|
2021-07-07 20:48:07 +02:00
|
|
|
Unlink(sysv::Unlink),
|
2021-07-07 19:19:19 +02:00
|
|
|
}
|
|
|
|
|
2021-12-03 14:50:23 +01:00
|
|
|
#[derive(Debug, Parser)]
|
2021-06-20 17:50:24 +02:00
|
|
|
#[clap(
|
|
|
|
version = crate_version!(),
|
|
|
|
author = crate_authors!(", "),
|
|
|
|
setting = AppSettings::SubcommandRequiredElseHelp,
|
2021-10-10 01:23:17 +02:00
|
|
|
global_setting = AppSettings::PropagateVersion,
|
2021-06-20 17:50:24 +02:00
|
|
|
global_setting = AppSettings::InferSubcommands,
|
|
|
|
)]
|
2021-06-30 22:46:33 +02:00
|
|
|
struct Opts {
|
2021-07-07 17:13:08 +02:00
|
|
|
/// Produce verbose output, multiple -v options increase the verbosity (max. 3)
|
|
|
|
#[clap(short, long, global = true, parse(from_occurrences))]
|
|
|
|
verbose: u32,
|
2021-07-07 19:19:19 +02:00
|
|
|
/// Backend to be used
|
2021-06-20 17:50:24 +02:00
|
|
|
#[clap(subcommand)]
|
2021-07-07 19:19:19 +02:00
|
|
|
backend: Backend,
|
2021-06-20 17:50:24 +02:00
|
|
|
}
|
2021-06-12 16:26:48 +02:00
|
|
|
|
2021-06-14 03:06:23 +02:00
|
|
|
fn main() -> Result<()> {
|
|
|
|
let opts: Opts = Opts::parse();
|
|
|
|
|
2021-07-07 17:13:08 +02:00
|
|
|
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or(
|
|
|
|
match opts.verbose {
|
|
|
|
0 => "warn",
|
|
|
|
1 => "info",
|
|
|
|
2 => "debug",
|
|
|
|
_ => "trace",
|
|
|
|
},
|
|
|
|
))
|
|
|
|
.init();
|
|
|
|
|
2021-07-07 19:19:19 +02:00
|
|
|
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 {
|
2021-07-07 20:23:04 +02:00
|
|
|
SysvCommand::Create(c) => c.run()?,
|
2021-07-08 17:44:46 +02:00
|
|
|
SysvCommand::Info(i) => i.run()?,
|
2021-07-08 14:46:10 +02:00
|
|
|
SysvCommand::List(l) => l.run()?,
|
2021-07-07 20:48:07 +02:00
|
|
|
SysvCommand::Unlink(u) => u.run()?,
|
2021-07-07 19:19:19 +02:00
|
|
|
},
|
2021-06-14 03:06:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
2021-06-12 16:26:48 +02:00
|
|
|
}
|