mqrs/src/main.rs
finga 9666e0788d Implement info command for SysV IPC mqs
The `list` command was refactored a little bit as well and the man
page and readme were updated.
2021-07-09 00:29:13 +02:00

82 lines
2 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),
Info(sysv::Info),
List(sysv::List),
Unlink(sysv::Unlink),
}
#[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()?,
SysvCommand::Info(i) => i.run()?,
SysvCommand::List(l) => l.run()?,
SysvCommand::Unlink(u) => u.run()?,
},
}
Ok(())
}