Compare commits

...

2 commits

Author SHA1 Message Date
finga c3b916255a mqrs: Implement send and recv of sysvmq [wip]
TBD: CHANGELOG.md and adapt to recent changes is sysvmq
2023-10-28 20:21:21 +02:00
finga e2cf753da0 sysvmq: Update rust edition to 2021
Update rust edition to 2021.
2023-10-28 20:21:21 +02:00
5 changed files with 104 additions and 14 deletions

View file

@ -1,5 +1,7 @@
use anyhow::Result;
use clap::{ArgAction, Parser};
use clap::Parser;
use log::Level;
use std::env;
mod posix;
mod sysv;
@ -30,6 +32,8 @@ enum SysvCommand {
Info(sysv::Info),
List(sysv::List),
Unlink(sysv::Unlink),
Send(sysv::Send),
Recv(sysv::Recv),
}
#[derive(Debug, Parser)]
@ -39,9 +43,9 @@ enum SysvCommand {
subcommand_required = true
)]
struct Opts {
/// Produce verbose output, multiple -v options increase the verbosity (max. 3)
#[clap(short, long, global = true, action = ArgAction::Count)]
verbose: u32,
/// Set a log level
#[arg(short, long, value_name = "LEVEL", default_value_t = Level::Info)]
pub log_level: Level,
/// Backend to be used
#[clap(subcommand)]
backend: Backend,
@ -50,15 +54,11 @@ struct Opts {
fn main() -> Result<()> {
let opts: Opts = Opts::parse();
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or(
match opts.verbose {
0 => "warn",
1 => "info",
2 => "debug",
_ => "trace",
},
))
.init();
if env::var("RUST_LOG").is_err() {
env::set_var("RUST_LOG", format!("{}", opts.log_level));
}
env_logger::init();
match opts.backend {
Backend::Posix(p) => match p {
@ -74,6 +74,8 @@ fn main() -> Result<()> {
SysvCommand::Info(i) => i.run()?,
SysvCommand::List(l) => l.run()?,
SysvCommand::Unlink(u) => u.run()?,
SysvCommand::Send(s) => s.run()?,
SysvCommand::Recv(r) => r.run()?,
},
}

View file

@ -1,9 +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;

42
src/sysv/recv.rs Normal file
View file

@ -0,0 +1,42 @@
use anyhow::Result;
// use chrono::DateTime;
use clap::Parser;
// use humantime::Duration;
use log::info;
use sysvmq::SysvMq;
/// Send a message to a message queue
#[derive(Debug, Parser)]
pub struct Recv {
// /// Set a different priority, priority >= 0
// #[clap(short, long, default_value = "0")]
// priority: u32,
// /// Do not block
// #[clap(short, long)]
// non_blocking: bool,
// /// Timeout, example "5h 23min 42ms"
// #[clap(short = 'o', long, conflicts_with = "deadline")]
// timeout: Option<String>,
// /// Deadline until messages are sent (format: "%Y-%m-%d %H:%M:%S")
// #[clap(short, long, conflicts_with = "timeout")]
// deadline: Option<String>,
// /// Name of the queue
// #[clap(value_name = "QUEUE")]
// queue: String,
/// Key of of the queue to write to
#[clap(value_name = "Key")]
key: i32,
// /// Message to be sent to the queue
// #[clap(value_name = "MESSAGE")]
// msg: String,
}
impl Recv {
pub fn run(&self) -> Result<()> {
let mq = SysvMq::<String>::new();
mq.open(self.key)?.recv();
Ok(())
}
}

42
src/sysv/send.rs Normal file
View file

@ -0,0 +1,42 @@
use anyhow::Result;
// use chrono::DateTime;
use clap::Parser;
// use humantime::Duration;
use log::info;
use sysvmq::SysvMq;
/// Send a message to a message queue
#[derive(Debug, Parser)]
pub struct Send {
// /// Set a different priority, priority >= 0
// #[clap(short, long, default_value = "0")]
// priority: u32,
// /// Do not block
// #[clap(short, long)]
// non_blocking: bool,
// /// Timeout, example "5h 23min 42ms"
// #[clap(short = 'o', long, conflicts_with = "deadline")]
// timeout: Option<String>,
// /// Deadline until messages are sent (format: "%Y-%m-%d %H:%M:%S")
// #[clap(short, long, conflicts_with = "timeout")]
// deadline: Option<String>,
// /// Name of the queue
// #[clap(value_name = "QUEUE")]
// queue: String,
/// Key of of the queue to write to
#[clap(value_name = "Key")]
key: i32,
/// Message to be sent to the queue
#[clap(value_name = "MESSAGE")]
msg: String,
}
impl Send {
pub fn run(&self) -> Result<()> {
let mq = SysvMq::<String>::new();
mq.open(self.key)?.send(self.msg.as_bytes());
Ok(())
}
}

View file

@ -1,7 +1,7 @@
[package]
name = "sysvmq"
version = "0.1.0"
edition = "2018"
edition = "2021"
authors = ["finga <mqrs@onders.org>"]
repository = "https://git.onders.org/finga/mqrs"
license = "GPL-3.0-or-later"