From e7b0b87259fe95f08b206d6e5ae02a7313983629 Mon Sep 17 00:00:00 2001 From: Dominic Gerhauser Date: Tue, 8 Apr 2025 17:03:44 +0200 Subject: [PATCH] simplify argument parsing --- src/main.rs | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9f60bc8..c73879e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -79,33 +79,28 @@ pub fn icon_cache_get(name: &'static str, size: u16) -> widget::icon::Icon { } /// Runs application with these settings -#[rustfmt::skip] fn main() -> Result<(), Box> { - let mut shell_program_opt = None; - let mut shell_args = Vec::new(); - let mut parse_flags = true; let mut daemonize = true; - for arg in env::args().skip(1) { - if parse_flags { - match arg.as_str() { - // These flags indicate the end of parsing flags - "-e" | "--command" | "--" => { - parse_flags = false; - } - "--no-daemon" => { - daemonize = false; - } - _ => { - //TODO: should this throw an error? - log::warn!("ignored argument {:?}", arg); - } + let mut args_iter = env::args().fuse(); + // more performant than an iterator adapter + _ = args_iter.next(); + for arg in args_iter.by_ref() { + match arg.as_str() { + // These flags indicate the end of parsing flags + "-e" | "--command" | "--" => { + break; + } + "--no-daemon" => { + daemonize = false; + } + _ => { + //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")))] if daemonize {