dev #2
@ -11,4 +11,5 @@ tokio = { version = "1.40.0", features = ["full"] }
|
|||||||
futures-util = "0.3.30"
|
futures-util = "0.3.30"
|
||||||
serde = { version = "1.0.210", features = ["derive"] }
|
serde = { version = "1.0.210", features = ["derive"] }
|
||||||
serde_json = "1.0.128"
|
serde_json = "1.0.128"
|
||||||
rson_rs = "0.2.1"
|
rson_rs = "0.2.1"
|
||||||
|
argh = "0.1.12"
|
||||||
|
20
src/main.rs
20
src/main.rs
@ -7,7 +7,8 @@ pub mod formats {
|
|||||||
mod notification;
|
mod notification;
|
||||||
use notification::{to_notif, Notification};
|
use notification::{to_notif, Notification};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::env;
|
// use std::env;
|
||||||
|
pub mod optparse;
|
||||||
|
|
||||||
use futures_util::stream::TryStreamExt;
|
use futures_util::stream::TryStreamExt;
|
||||||
use zbus::{message::Body, Connection, Result};
|
use zbus::{message::Body, Connection, Result};
|
||||||
@ -32,6 +33,7 @@ fn server_properties() -> HashMap<String, String> {
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
|
/*
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
let op_format: &str = if args.len() == 1 || args[1] == "j" {
|
let op_format: &str = if args.len() == 1 || args[1] == "j" {
|
||||||
"j" // Default value, json format
|
"j" // Default value, json format
|
||||||
@ -41,9 +43,17 @@ async fn main() -> Result<()> {
|
|||||||
"r" // rson format
|
"r" // rson format
|
||||||
} else {
|
} else {
|
||||||
"j"
|
"j"
|
||||||
};
|
}; */
|
||||||
|
|
||||||
let verbose: bool = (args.len() > 2) && (args[2] == "v");
|
let args: optparse::Cli = argh::from_env();
|
||||||
|
let op_format = match args.format {
|
||||||
|
Some(value) => value.clone(), // Cloning the owned String
|
||||||
|
None => "j".to_string(), // Using the default value as a String
|
||||||
|
};
|
||||||
|
|
||||||
|
let verbose = args.verbose;
|
||||||
|
|
||||||
|
//let verbose: bool = (args.len() > 2) && (args[2] == "v");
|
||||||
|
|
||||||
let connection = Connection::session().await?;
|
let connection = Connection::session().await?;
|
||||||
connection
|
connection
|
||||||
@ -117,12 +127,12 @@ async fn main() -> Result<()> {
|
|||||||
// Convert the msg body to a Notification object
|
// Convert the msg body to a Notification object
|
||||||
let notif: Notification = to_notif(&msg_body)?;
|
let notif: Notification = to_notif(&msg_body)?;
|
||||||
// Handle the notif
|
// Handle the notif
|
||||||
match op_format {
|
match op_format.as_str() {
|
||||||
"j" => {
|
"j" => {
|
||||||
println!("{}", ¬if.json()); // Print the json version
|
println!("{}", ¬if.json()); // Print the json version
|
||||||
}
|
}
|
||||||
"r" => {
|
"r" => {
|
||||||
println!("{}", ¬if.rson()); // Print the plain version
|
println!("{}", ¬if.rson()); // Print the rson version
|
||||||
}
|
}
|
||||||
"p" => {
|
"p" => {
|
||||||
println!("{}\n", ¬if.plain()); // Print the plain version
|
println!("{}\n", ¬if.plain()); // Print the plain version
|
||||||
|
@ -51,14 +51,11 @@ impl Notification {
|
|||||||
|
|
||||||
// Key:Val pairs of actions
|
// Key:Val pairs of actions
|
||||||
pub fn actions(&self) -> Vec<(String, String)> {
|
pub fn actions(&self) -> Vec<(String, String)> {
|
||||||
self.actions
|
self.actions
|
||||||
.chunks(2)
|
.chunks(2)
|
||||||
.map(|chunk|
|
.map(|chunk| (chunk[0].clone(), chunk[1].clone()))
|
||||||
(chunk[0].clone(),
|
.collect()
|
||||||
chunk[1].clone())
|
}
|
||||||
)
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hints
|
// Hints
|
||||||
pub fn hints(&self) -> &HashMap<String, OwnedValue> {
|
pub fn hints(&self) -> &HashMap<String, OwnedValue> {
|
||||||
|
13
src/optparse.rs
Normal file
13
src/optparse.rs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
use argh::FromArgs;
|
||||||
|
|
||||||
|
#[derive(FromArgs)]
|
||||||
|
/// Print desktop notifications
|
||||||
|
pub struct Cli {
|
||||||
|
/// select output format: j(json), r(rson), p(plain)
|
||||||
|
#[argh(option, short = 'f')]
|
||||||
|
pub format: Option<String>,
|
||||||
|
|
||||||
|
/// verbose mode
|
||||||
|
#[argh(switch, short = 'v')]
|
||||||
|
pub verbose: bool,
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user