use anyhow::Result; use clap::{crate_authors, crate_version, AppSettings, 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( version = crate_version!(), author = crate_authors!(", "), setting = AppSettings::SubcommandRequiredElseHelp, global_setting = AppSettings::PropagateVersion, 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(()) }