simplify argument parsing

This commit is contained in:
Dominic Gerhauser 2025-04-08 17:03:44 +02:00 • committed by Jeremy Soller
parent ae817d850f
commit e7b0b87259

View file

@ -79,33 +79,28 @@ pub fn icon_cache_get(name: &'static str, size: u16) -> widget::icon::Icon {
} }
/// Runs application with these settings /// Runs application with these settings
#[rustfmt::skip]
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut shell_program_opt = None;
let mut shell_args = Vec::new();
let mut parse_flags = true;
let mut daemonize = true; let mut daemonize = true;
for arg in env::args().skip(1) { let mut args_iter = env::args().fuse();
if parse_flags { // more performant than an iterator adapter
match arg.as_str() { _ = args_iter.next();
// These flags indicate the end of parsing flags for arg in args_iter.by_ref() {
"-e" | "--command" | "--" => { match arg.as_str() {
parse_flags = false; // These flags indicate the end of parsing flags
} "-e" | "--command" | "--" => {
"--no-daemon" => { break;
daemonize = false; }
} "--no-daemon" => {
_ => { daemonize = false;
//TODO: should this throw an error? }
log::warn!("ignored argument {:?}", arg); _ => {
} //TODO: should this throw an error?
log::warn!("ignored argument {:?}", arg);
} }
} else if shell_program_opt.is_none() {
shell_program_opt = Some(arg);
} else {
shell_args.push(arg);
} }
} }
let shell_program_opt = args_iter.next();
let shell_args = Vec::from_iter(args_iter);
#[cfg(all(unix, not(target_os = "redox")))] #[cfg(all(unix, not(target_os = "redox")))]
if daemonize { if daemonize {