From fe877b230ce876f5c6694934e83c845e970a094d Mon Sep 17 00:00:00 2001 From: finga Date: Mon, 14 Jun 2021 03:27:24 +0200 Subject: [PATCH] Remove a message queue --- src/cli.rs | 3 ++- src/main.rs | 2 ++ src/unlink.rs | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/unlink.rs diff --git a/src/cli.rs b/src/cli.rs index dd1d8af..69e1d7a 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,4 +1,4 @@ -use crate::create::Create; +use crate::{create::Create, unlink::Unlink}; use clap::{crate_authors, crate_version, AppSettings, Clap}; #[derive(Clap, Debug)] @@ -20,4 +20,5 @@ pub struct Opts { #[derive(Clap, Debug)] pub enum Command { Create(Create), + Unlink(Unlink), } diff --git a/src/main.rs b/src/main.rs index 4d99c10..ab0ffe7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use clap::Clap; mod cli; mod create; +mod unlink; use cli::{Command, Opts}; @@ -11,6 +12,7 @@ fn main() -> Result<()> { match opts.command { Command::Create(c) => c.run(opts.verbose)?, + Command::Unlink(u) => u.run(opts.verbose)?, } Ok(()) diff --git a/src/unlink.rs b/src/unlink.rs new file mode 100644 index 0000000..71eaac4 --- /dev/null +++ b/src/unlink.rs @@ -0,0 +1,22 @@ +use anyhow::Result; +use clap::Clap; + +/// Delete a message queue +#[derive(Clap, Debug)] +pub struct Unlink { + /// Name of the queue + #[clap(value_name = "QNAME")] + pub queue: String, +} + +impl Unlink { + pub fn run(&self, verbose: bool) -> Result<()> { + posixmq::remove_queue(&self.queue)?; + + if verbose { + println!("Removed message queue: {}", &self.queue); + } + + Ok(()) + } +}