mqrs/src/main.rs
finga 4d200bb5f3 Implement creation of SysV IPC message queues
This adds the `sysvmq` package which handles SysV IPC message queues.
For consistency the parameter for `permissions` is renamed to `mode`
also for POSIX message queues.
2021-07-07 20:31:16 +02:00

76 lines
1.8 KiB
Rust

use anyhow::Result;
use clap::{crate_authors, crate_version, AppSettings, Clap};
mod posix;
mod sysv;
#[derive(Clap, Debug)]
enum Backend {
/// Handle POSIX message queues
Posix(PosixCommand),
/// Handle SysV message queues
Sysv(SysvCommand),
}
#[derive(Clap, Debug)]
enum PosixCommand {
Create(posix::Create),
Info(posix::Info),
List(posix::List),
Unlink(posix::Unlink),
Send(posix::Send),
Recv(posix::Recv),
}
#[derive(Clap, Debug)]
enum SysvCommand {
Create(sysv::Create),
}
#[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,
/// 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()?,
},
}
Ok(())
}