Refactor commands to support different backends

Therefore also the `sysv` backend is intoduced to prepare for future
support. The man page and the readme are updated so far.
This commit is contained in:
finga 2021-07-07 19:19:19 +02:00
parent 4020f062ef
commit 9aae14feae
3 changed files with 72 additions and 36 deletions

View file

@ -4,7 +4,15 @@ use clap::{crate_authors, crate_version, AppSettings, Clap};
mod posix;
#[derive(Clap, Debug)]
enum Command {
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),
@ -13,6 +21,10 @@ enum Command {
Recv(posix::Recv),
}
#[derive(Clap, Debug)]
enum SysvCommand {
}
#[derive(Clap, Debug)]
#[clap(
version = crate_version!(),
@ -25,8 +37,9 @@ 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)]
command: Command,
backend: Backend,
}
fn main() -> Result<()> {
@ -42,13 +55,17 @@ fn main() -> Result<()> {
))
.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()?,
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 {
},
}
Ok(())