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,18 +79,16 @@ 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
_ = args_iter.next();
for arg in args_iter.by_ref() {
match arg.as_str() { match arg.as_str() {
// These flags indicate the end of parsing flags // These flags indicate the end of parsing flags
"-e" | "--command" | "--" => { "-e" | "--command" | "--" => {
parse_flags = false; break;
} }
"--no-daemon" => { "--no-daemon" => {
daemonize = false; daemonize = false;
@ -100,12 +98,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
log::warn!("ignored argument {:?}", arg); 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 {