Refactor commands to support different backends

Therefore also the `sysv` backend is intoduced to prepare for future
support. The man page and the readme are updated so far.
This commit is contained in:
finga 2021-07-07 19:19:19 +02:00
parent 4020f062ef
commit 9aae14feae
3 changed files with 72 additions and 36 deletions

View file

@ -46,31 +46,38 @@ from `target/{debug,release}/mqrs` depending on which
one you built. one you built.
## Using `mqrs` ## Using `mqrs`
`mqrs` supports five commands: `create`, `info`, `list`, `unlink`, Depending on which backend you want to use there are different subsets
`send` and `recv`. All commands do not have to be specified fully. If of subcommands. Following backends are supported:
the command is clearly distinguishable from all the others, it does - `posix`: Uses POSIX message queues
not have to be completed further. - `sysv`: Uses SysV IPC message queues
### Create a message queue If a command is clearly distinguishable from all the others,
it does not have to be completed further.
### POSIX message queues
The POSIX backend supports six commands: `create`, `info`, `list`,
`unlink`, `send` and `recv`.
#### Create a message queue
Use the `create` command to create a new POSIX message queue. Following Use the `create` command to create a new POSIX message queue. Following
optional arguments are supported: optional arguments are supported:
- `-c`, `--capacity`: Maximum number of messages in the queue - `-c`, `--capacity`: Maximum number of messages in the queue
- `-p`, `--permissions`: Permissions (octal) to create the queue with - `-p`, `--permissions`: Permissions (octal) to create the queue with
- `-s`, `--msgsize`: Message size in bytes - `-s`, `--msgsize`: Message size in bytes
### Print information about a message queue #### Print information about a message queue
Use the `info` command to print further information about a message Use the `info` command to print further information about a message
queue. queue.
### List all message queues #### List all message queues
Use the `list` command to print a list of all message Use the `list` command to print a list of all message
queues. Following option argument is supported: queues. Following option argument is supported:
- `-a`, `--all`: Print all available information - `-a`, `--all`: Print all available information
### Delete a message queue #### Delete a message queue
Use the `unlink` command to delete a message queue. Use the `unlink` command to delete a message queue.
### Send a message to a queue #### Send a message to a queue
Use the `send` command to send a message to a message queue. Following Use the `send` command to send a message to a message queue. Following
optional arguments are supported: optional arguments are supported:
- `-n`, `--non-blocking`: Do not block - `-n`, `--non-blocking`: Do not block
@ -80,7 +87,7 @@ optional arguments are supported:
default, priority >= 0 [default: 0] default, priority >= 0 [default: 0]
- `-o`, `--timeout <timeout>`: As for example in "5h 23min 42ms" - `-o`, `--timeout <timeout>`: As for example in "5h 23min 42ms"
### Receive a message from a queue #### Receive a message from a queue
Use the `recv` command to receive one or more messages from a message Use the `recv` command to receive one or more messages from a message
queue. Following optional arguments are supported: queue. Following optional arguments are supported:
- `-f`, `--follow`: Print messages as they are received - `-f`, `--follow`: Print messages as they are received
@ -89,3 +96,6 @@ queue. Following optional arguments are supported:
- `-d`, `--deadline <deadline>`: Deadline until messages are received - `-d`, `--deadline <deadline>`: Deadline until messages are received
(format: `%Y-%m-%d %H:%M:%S`) (format: `%Y-%m-%d %H:%M:%S`)
- `-o,` `--timeout <timeout>`: As for example in "5h 23min 42ms" - `-o,` `--timeout <timeout>`: As for example in "5h 23min 42ms"
### SysV IPC message queues
The SysV IPC backend supports no commands yet.

43
mqrs.1
View file

@ -1,12 +1,34 @@
.\" Manpage for mqrs .\" Manpage for mqrs
.TH man 1 "27 June 2021" "0.1.1" "mqrs man page" .TH man 1 "7 July 2021" "0.1.1" "mqrs man page"
.SH NAME .SH NAME
mqrs \- Handle POSIX message queues mqrs \- Handle POSIX message queues
.SH SYNOPSIS .SH SYNOPSIS
.B mqrs [\-h] [\-\-help] [\-v] [\-\-verbose] [\-V] [\-\-version] [SUBCOMMAND] .B mqrs [\-h] [\-\-help] [\-v] [\-\-verbose] [\-V] [\-\-version] [SUBCOMMAND]
.SH DESCRIPTION .SH DESCRIPTION
.B mqrs .B mqrs
is a small cli program to handle POSIX message queues. Supported commands are is a small cli program to handle message queues. Depending on which
backend you want to use there are different subsets of
subcommands. Following backends are supported:
.B posix\
and
.B sysv\
.
If a command is clearly distinguishable from all the others, it does
not have to be completed further.
.SH OPTIONS
.TP 8
.B \-h, \-\-help
Prints help information
.TP 8
.B \-v, \-\-verbose
Produce verbose output, multiple -v options increase the verbosity
(max. 3)
.TP 8
.B \-V, \-\-version
Prints version information
.SH POSIX MESSAGE QUEUE SUBCOMMANDS
The POSIX backend supports six commands:
.B create\ .B create\
, ,
.B info\ .B info\
@ -19,21 +41,6 @@ is a small cli program to handle POSIX message queues. Supported commands are
and and
.B recv .B recv
. .
All commands do not have to be specified fully. If the command is
clearly distinguishable from all the others, it is not needed to
complete it further.
.SH OPTIONS
.TP 8
.B \-h, \-\-help
Prints help information
.TP 8
.B \-v, \-\-verbose
Produce verbose output, multiple -v options increase the verbosity
(max. 3)
.TP 8
.B \-V, \-\-version
Prints version information
.SH SUBCOMMANDS
.SS create [FLAGS] [OPTIONS] \fI<QUEUE>\fP .SS create [FLAGS] [OPTIONS] \fI<QUEUE>\fP
Create a new POSIX message queue. Create a new POSIX message queue.
.TP 8 .TP 8
@ -202,6 +209,8 @@ Prints help information
.B \-v, \-\-verbose .B \-v, \-\-verbose
Produce verbose output Produce verbose output
.RE .RE
.SH SYSV IPC MESSAGE QUEUE SUBCOMMANDS
The SysV IPC backend supports no commands yet.
.SH SEE ALSO .SH SEE ALSO
mq_overview(7) mq_overview(7)
.SH BUGS .SH BUGS

View file

@ -4,7 +4,15 @@ use clap::{crate_authors, crate_version, AppSettings, Clap};
mod posix; mod posix;
#[derive(Clap, Debug)] #[derive(Clap, Debug)]
enum Command { enum Backend {
/// Handle POSIX message queues
Posix(PosixCommand),
/// Handle SysV message queues
Sysv(SysvCommand),
}
#[derive(Clap, Debug)]
enum PosixCommand {
Create(posix::Create), Create(posix::Create),
Info(posix::Info), Info(posix::Info),
List(posix::List), List(posix::List),
@ -13,6 +21,10 @@ enum Command {
Recv(posix::Recv), Recv(posix::Recv),
} }
#[derive(Clap, Debug)]
enum SysvCommand {
}
#[derive(Clap, Debug)] #[derive(Clap, Debug)]
#[clap( #[clap(
version = crate_version!(), version = crate_version!(),
@ -25,8 +37,9 @@ struct Opts {
/// Produce verbose output, multiple -v options increase the verbosity (max. 3) /// Produce verbose output, multiple -v options increase the verbosity (max. 3)
#[clap(short, long, global = true, parse(from_occurrences))] #[clap(short, long, global = true, parse(from_occurrences))]
verbose: u32, verbose: u32,
/// Backend to be used
#[clap(subcommand)] #[clap(subcommand)]
command: Command, backend: Backend,
} }
fn main() -> Result<()> { fn main() -> Result<()> {
@ -42,13 +55,17 @@ fn main() -> Result<()> {
)) ))
.init(); .init();
match opts.command { match opts.backend {
Command::Create(c) => c.run()?, Backend::Posix(p) => match p {
Command::Info(i) => i.run()?, PosixCommand::Create(c) => c.run()?,
Command::Unlink(u) => u.run()?, PosixCommand::Info(i) => i.run()?,
Command::Send(s) => s.run()?, PosixCommand::List(l) => l.run()?,
Command::Recv(r) => r.run()?, PosixCommand::Unlink(u) => u.run()?,
Command::List(l) => l.run()?, PosixCommand::Send(s) => s.run()?,
PosixCommand::Recv(r) => r.run()?,
},
Backend::Sysv(s) => match s {
},
} }
Ok(()) Ok(())