Add new subcommand list

Also add it to the readme and manpage.
This commit is contained in:
finga 2021-07-07 18:27:41 +02:00
parent 12b117db7e
commit 4020f062ef
5 changed files with 90 additions and 6 deletions

View file

@ -46,10 +46,10 @@ from `target/{debug,release}/mqrs` depending on which
one you built.
## Using `mqrs`
`mqrs` supports five commands: `create`, `info`, `unlink`, `send` and
`recv`. All commands do not have to be specified fully. If the
command is clearly distinguishable from all the others, it does not
have to be completed further.
`mqrs` supports five commands: `create`, `info`, `list`, `unlink`,
`send` and `recv`. All commands do not have to be specified fully. If
the command is clearly distinguishable from all the others, it does
not have to be completed further.
### Create a message queue
Use the `create` command to create a new POSIX message queue. Following
@ -62,6 +62,11 @@ optional arguments are supported:
Use the `info` command to print further information about a message
queue.
### List all message queues
Use the `list` command to print a list of all message
queues. Following option argument is supported:
- `-a`, `--all`: Print all available information
### Delete a message queue
Use the `unlink` command to delete a message queue.

21
mqrs.1
View file

@ -11,6 +11,8 @@ is a small cli program to handle POSIX message queues. Supported commands are
,
.B info\
,
.B list\
,
.B unlink\
,
.B send
@ -18,8 +20,8 @@ and
.B recv
.
All commands do not have to be specified fully. If the command is
clearly distinguishable from all the others, it does not have to be
completed further.
clearly distinguishable from all the others, it is not needed to
complete it further.
.SH OPTIONS
.TP 8
.B \-h, \-\-help
@ -90,6 +92,21 @@ Prints help information
.B \-v, \-\-verbose
Produce verbose output
.RE
.SS list [FLAGS]
Print a list of all existing POSIX message queues.
.TP 8
.SS FLAGS
.RS
.TP 8
.B \-h, \-\-help
Prints help information
.TP 8
.B \-v, \-\-verbose
Produce verbose output
.TP 8
.B \-a, \-\-all
Print all available information
.RE
.SS recv [FLAGS] [OPTIONS] \fI<QUEUE>\fP
Receive and print one or more messages message from a message queue.
.TP 8

View file

@ -7,6 +7,7 @@ mod posix;
enum Command {
Create(posix::Create),
Info(posix::Info),
List(posix::List),
Unlink(posix::Unlink),
Send(posix::Send),
Recv(posix::Recv),
@ -47,6 +48,7 @@ fn main() -> Result<()> {
Command::Unlink(u) => u.run()?,
Command::Send(s) => s.run()?,
Command::Recv(r) => r.run()?,
Command::List(l) => l.run()?,
}
Ok(())

View file

@ -1,11 +1,13 @@
mod create;
mod info;
mod list;
mod recv;
mod send;
mod unlink;
pub use create::Create;
pub use info::Info;
pub use list::List;
pub use recv::Recv;
pub use send::Send;
pub use unlink::Unlink;

58
src/posix/list.rs Normal file
View file

@ -0,0 +1,58 @@
use anyhow::{anyhow, Result};
use chrono::{DateTime, Local};
use clap::Clap;
use log::warn;
use std::{fs, os::unix::fs::PermissionsExt};
/// Print information about an existing message queue
#[derive(Clap, Debug)]
pub struct List {
/// Show all parameters
#[clap(short, long)]
all: bool,
}
impl List {
pub fn run(&self) -> Result<()> {
match self.all {
false => println!("Name"),
true => println!(
"{0: <10} {1: <10} {2: <12} {3: <26} {4: <26}",
"Name", "Size", "Permissions", "Modified", "Accessed",
),
}
for mq in fs::read_dir("/dev/mqueue")? {
match mq {
Ok(mq) => {
print!(
"/{0: <10}",
mq.file_name().into_string().map_err(|e| anyhow!(
"Could not convert queue name to string: {:?}",
e
))?
);
if self.all {
let metadata = mq.metadata()?;
let modified: DateTime<Local> = metadata.modified()?.into();
let accessed: DateTime<Local> = metadata.accessed()?.into();
print!(
"{0: <10} {1: <12o} {2: <26} {3: <26}",
metadata.len(),
metadata.permissions().mode(),
modified,
accessed,
);
}
println!();
}
Err(e) => warn!("Could not read file: {:?}", e),
}
}
Ok(())
}
}