Print infos about a message queue
This commit is contained in:
parent
fe877b230c
commit
33f0bf8312
3 changed files with 28 additions and 1 deletions
|
@ -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),
|
||||
}
|
||||
|
|
24
src/info.rs
Normal file
24
src/info.rs
Normal 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(())
|
||||
}
|
||||
}
|
|
@ -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)?,
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue