fixed option parsing
This commit is contained in:
parent
05833c5d99
commit
4a708bb6a0
31
src/main.rs
31
src/main.rs
@ -33,27 +33,20 @@ fn server_properties() -> HashMap<String, String> {
|
||||
|
||||
#[tokio::main]
|
||||
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 op_format = match args.format {
|
||||
Some(value) => value.clone(), // Cloning the owned String
|
||||
None => "j".to_string(), // Using the default value as a String
|
||||
Some(value) => value.clone(),
|
||||
None => "j".to_string(),
|
||||
};
|
||||
|
||||
let verbose = args.verbose;
|
||||
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: bool = (args.len() > 2) && (args[2] == "v");
|
||||
let verbose = args.verbose;
|
||||
|
||||
let connection = Connection::session().await?;
|
||||
connection
|
||||
@ -85,9 +78,6 @@ async fn main() -> Result<()> {
|
||||
println!("GetAll request received for interface: {interface_name}");
|
||||
}
|
||||
} else {
|
||||
if verbose {
|
||||
println!("Unknown interface requested: {interface_name}");
|
||||
}
|
||||
// Reply with an error
|
||||
connection
|
||||
.reply_error(
|
||||
@ -96,6 +86,9 @@ async fn main() -> Result<()> {
|
||||
&"Unknown interface".to_string(),
|
||||
)
|
||||
.await?;
|
||||
if verbose {
|
||||
println!("Unknown interface requested: {interface_name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
"GetServerInformation" => {
|
||||
|
@ -3,7 +3,7 @@ use argh::FromArgs;
|
||||
#[derive(FromArgs)]
|
||||
/// Print desktop notifications
|
||||
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')]
|
||||
pub format: Option<String>,
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user