dev #2

Merged
candifloss merged 10 commits from dev into main 2024-09-27 10:06:26 +00:00
2 changed files with 15 additions and 22 deletions
Showing only changes of commit 4a708bb6a0 - Show all commits

View File

@ -33,27 +33,20 @@ 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 op_format: &str = if args.len() == 1 || args[1] == "j" {
"j" // Default value, json format
} else if args[1] == "p" {
"p" // Plain format
} else if args[1] == "r" {
"r" // rson format
} else {
"j"
}; */
let args: optparse::Cli = argh::from_env(); let args: optparse::Cli = argh::from_env();
let op_format = match args.format { let op_format = match args.format {
Some(value) => value.clone(), // Cloning the owned String Some(value) => value.clone(),
None => "j".to_string(), // Using the default value as a String None => "j".to_string(),
}; };
let verbose = args.verbose;
//let verbose: bool = (args.len() > 2) && (args[2] == "v"); if !["r", "j", "p"].contains(&op_format.as_str()) {
return Err(zbus::Error::from(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"Invalid output format",
)));
}
let verbose = args.verbose;
let connection = Connection::session().await?; let connection = Connection::session().await?;
connection connection
@ -85,9 +78,6 @@ async fn main() -> Result<()> {
println!("GetAll request received for interface: {interface_name}"); println!("GetAll request received for interface: {interface_name}");
} }
} else { } else {
if verbose {
println!("Unknown interface requested: {interface_name}");
}
// Reply with an error // Reply with an error
connection connection
.reply_error( .reply_error(
@ -96,6 +86,9 @@ async fn main() -> Result<()> {
&"Unknown interface".to_string(), &"Unknown interface".to_string(),
) )
.await?; .await?;
if verbose {
println!("Unknown interface requested: {interface_name}");
}
} }
} }
"GetServerInformation" => { "GetServerInformation" => {

View File

@ -3,11 +3,11 @@ use argh::FromArgs;
#[derive(FromArgs)] #[derive(FromArgs)]
/// Print desktop notifications /// Print desktop notifications
pub struct Cli { pub struct Cli {
/// select output format: j(json), r(rson), p(plain) /// select output format: r(rson), j(json, default), p(plain)
#[argh(option, short = 'f')] #[argh(option, short = 'f')]
pub format: Option<String>, pub format: Option<String>,
/// verbose mode /// verbose mode
#[argh(switch, short = 'v')] #[argh(switch, short = 'v')]
pub verbose: bool, pub verbose: bool,
} }