mqrs/src/sysv/unlink.rs
finga f4796e7da6 Refactor sysvmq::unlink_* and check for error
Use `sysvmq::id_from_key(key)` to receive the id of a queue identified
with `key`. Here an error check is added as well. Adapt
`Sysv::Unlink::run()` to comply with that change.
2021-07-08 14:20:53 +02:00

38 lines
851 B
Rust

use anyhow::Result;
use clap::Clap;
use log::info;
/// Delete a message queue
#[derive(Clap, Debug)]
pub struct Unlink {
/// Id of the queue
#[clap(
long,
short,
required_unless_present_any = &["key"],
conflicts_with = "key"
)]
id: Option<i32>,
/// Key of the queue
#[clap(long, short, required_unless_present_any = &["id"], conflicts_with = "id")]
key: Option<i32>,
}
impl Unlink {
pub fn run(&self) -> Result<()> {
if let Some(id) = self.id {
sysvmq::unlink_id(id)?;
info!("Removed message queue with id: {}", id);
} else if let Some(key) = self.key {
let id = sysvmq::id_from_key(key)?;
sysvmq::unlink_id(id)?;
info!("Removed message queue key: {} (id: {})", key, id);
}
Ok(())
}
}