Search code examples
rustcommand-line-argumentsclap

How do I use Clap to parse filenames?


I got this:

let args: Vec::<String> = std::env::args().collect();
let matches = App::new("Rust grader")
                    .author("Arkadiusz Bulski <arek.bulski@gmail.com>")
                    .arg(Arg::with_name("noprofile")
                            .long("noprofile")
                            .takes_value(false)
                            .help("Disable profiling, save time"))
                    .get_matches();
let config = matches.value_of("noprofile");

And a usage: ./binary-runner --noprofile -- tsp-arekbulski-*.rs

How can I get this clap app to recognize filenames?

Error:

error: Found argument 'tsp-arekbulski-01-trivial.rs' which wasn't expected, or isn't valid in this context

USAGE:
    binary-runner --noprofile

Solution

  • Solved it:

    let matches = App::new("Rust runner")
                        .author("Arkadiusz Bulski <arek.bulski@gmail.com>")
                        .arg(Arg::with_name("sources")
                                .multiple(true)
                                .help("Use this to pass argfilenames"))
                        .get_matches();