Print infos about a message queue

This commit is contained in:
finga 2021-06-14 03:51:26 +02:00
parent fe877b230c
commit 33f0bf8312
3 changed files with 28 additions and 1 deletions

View file

@ -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}; use clap::{crate_authors, crate_version, AppSettings, Clap};
#[derive(Clap, Debug)] #[derive(Clap, Debug)]
@ -20,5 +20,6 @@ pub struct Opts {
#[derive(Clap, Debug)] #[derive(Clap, Debug)]
pub enum Command { pub enum Command {
Create(Create), Create(Create),
Info(Info),
Unlink(Unlink), Unlink(Unlink),
} }

24
src/info.rs Normal file
View file

@ -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(())
}
}

View file

@ -3,6 +3,7 @@ use clap::Clap;
mod cli; mod cli;
mod create; mod create;
mod info;
mod unlink; mod unlink;
use cli::{Command, Opts}; use cli::{Command, Opts};
@ -12,6 +13,7 @@ fn main() -> Result<()> {
match opts.command { match opts.command {
Command::Create(c) => c.run(opts.verbose)?, Command::Create(c) => c.run(opts.verbose)?,
Command::Info(i) => i.run()?,
Command::Unlink(u) => u.run(opts.verbose)?, Command::Unlink(u) => u.run(opts.verbose)?,
} }