Program outputs `Unknown option` even though arguments are parsed

⚓ Rust    📅 2025-10-26    👤 surdeus    👁️ 3      

surdeus

I am creating an application using Rust + GTK4 + libadwaita and currently in the process of creating some launcher arguments using std::env::args(), testing it using an argument --trace. When I build and run my project (compile resources and then cargo run -- --trace), the program fails with Unknown option --trace. Here is my code for the argument parsing:

use simple_logger::SimpleLogger;

fn main() {
    let args = std::env::args().skip(1);
    for arg in args {
        match arg.as_str() {
            "--trace" => {
                println!("Starting log at trace level");
                SimpleLogger::new().init().unwrap();
            }
            _ => {
                eprintln!("Unknown argument {arg}");
                std::process::exit(1);
            }
        }
    }

    adw::init().expect("Failed to initialize libadwaita");
    gtk::init().expect("Failed to initialize GTK4");

    // ... initialize the app
}

Any responses is helpful because I have no clue why this is happening.

1 post - 1 participant

Read full topic

🏷️ Rust_feed