From 33f0bf8312faec4e3ffbf9fbd24255bee047d450 Mon Sep 17 00:00:00 2001 From: finga Date: Mon, 14 Jun 2021 03:51:26 +0200 Subject: [PATCH] Print infos about a message queue --- src/cli.rs | 3 ++- src/info.rs | 24 ++++++++++++++++++++++++ src/main.rs | 2 ++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/info.rs diff --git a/src/cli.rs b/src/cli.rs index 69e1d7a..5ef375c 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,4 +1,4 @@ -use crate::{create::Create, unlink::Unlink}; +use crate::{create::Create, unlink::Unlink, info::Info}; use clap::{crate_authors, crate_version, AppSettings, Clap}; #[derive(Clap, Debug)] @@ -20,5 +20,6 @@ pub struct Opts { #[derive(Clap, Debug)] pub enum Command { Create(Create), + Info(Info), Unlink(Unlink), } diff --git a/src/info.rs b/src/info.rs new file mode 100644 index 0000000..e2be5ba --- /dev/null +++ b/src/info.rs @@ -0,0 +1,24 @@ +use anyhow::Result; +use clap::Clap; +use posixmq::PosixMq; + +/// Print information about an existing message queue +#[derive(Clap, Debug)] +pub struct Info { + /// Name of the queue + #[clap(value_name = "QNAME")] + pub queue: String, +} + +impl Info { + pub fn run(&self) -> Result<()> { + let attrs = PosixMq::open(&self.queue)?.attributes()?; + + println!( + "Message queue: {}, msg_max: {}, msgsize_max: {}, current_messages: {}", + &self.queue, &attrs.capacity, &attrs.max_msg_len, &attrs.current_messages + ); + + Ok(()) + } +} diff --git a/src/main.rs b/src/main.rs index ab0ffe7..ec3e3c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use clap::Clap; mod cli; mod create; +mod info; mod unlink; use cli::{Command, Opts}; @@ -12,6 +13,7 @@ fn main() -> Result<()> { match opts.command { Command::Create(c) => c.run(opts.verbose)?, + Command::Info(i) => i.run()?, Command::Unlink(u) => u.run(opts.verbose)?, }