option fixes

This commit is contained in:
Candifloss 2024-09-27 00:51:37 +05:30
parent 5bcddfbad9
commit a6b95bad57

View File

@ -7,7 +7,6 @@ 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;
pub mod optparse; pub mod optparse;
use futures_util::stream::TryStreamExt; use futures_util::stream::TryStreamExt;
@ -33,19 +32,27 @@ fn server_properties() -> HashMap<String, String> {
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
// Options
let args: optparse::Cli = argh::from_env(); let args: optparse::Cli = argh::from_env();
// Format: r|j|p
let op_format = match args.format { let op_format = match args.format {
Some(value) => value.clone(), Some(value) => {
// Reject invalid format option
if ["r", "j", "p"].contains(&value.as_str()) {
value.clone()
} else {
// Exit with error code
return Err(zbus::Error::from(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"Invalid output format",
)));
}
}
None => "j".to_string(), None => "j".to_string(),
}; };
if !["r", "j", "p"].contains(&op_format.as_str()) { // Verbose mode. Off/false by default
return Err(zbus::Error::from(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"Invalid output format",
)));
}
let verbose = args.verbose; let verbose = args.verbose;
let connection = Connection::session().await?; let connection = Connection::session().await?;
@ -131,12 +138,12 @@ async fn main() -> Result<()> {
println!("{}\n", &notif.plain()); // Print the plain version println!("{}\n", &notif.plain()); // Print the plain version
} }
_ => { _ => {
println!("Onkown output format."); println!("Onkown output format."); // This is probably unreachable
} }
} }
} }
"CloseNotification" => { "CloseNotification" => {
// Client sent a close signal. Extract notification ID of the notif to be closed from the message body // Client sent a 'close' signal. Extract notification ID of the notif to be closed from the message body
let notification_id: u32 = msg.body().deserialize()?; // This method has only one parameter, the id let notification_id: u32 = msg.body().deserialize()?; // This method has only one parameter, the id
// Tracking notifications by their IDs, closing them, and other features may be implemented later // Tracking notifications by their IDs, closing them, and other features may be implemented later