12 stable releases

2.2.1 Jan 27, 2024
2.2.1-rc Dec 18, 2023
2.2.0 Sep 24, 2023
2.1.0 Aug 14, 2022
0.1.0 Nov 17, 2017

#5 in Windows APIs

Download history 12816/week @ 2023-12-23 14533/week @ 2023-12-30 16917/week @ 2024-01-06 20360/week @ 2024-01-13 19578/week @ 2024-01-20 22883/week @ 2024-01-27 20381/week @ 2024-02-03 19241/week @ 2024-02-10 21743/week @ 2024-02-17 32900/week @ 2024-02-24 38327/week @ 2024-03-02 38751/week @ 2024-03-09 32678/week @ 2024-03-16 27439/week @ 2024-03-23 29017/week @ 2024-03-30 18911/week @ 2024-04-06

112,101 downloads per month
Used in 170 crates (38 directly)

Apache-2.0 OR MIT

27KB
484 lines

Wild::args for Rust

Allows Rust applications support wildcard arguments (*foo*, file.???, *.log.[0-9], etc.) on command-line, uniformly on all platforms, including Windows.

Unix shells automatically interpret wildcard arguments and pass them expanded (already converted to file names) to applications, but Windows' cmd.exe doesn't do that. For consistent cross-platform behavior, this crate emulates Unix-like expansion on Windows. You only need to use wild::args() instead of std::env::args().

It is more robust than using glob() on values from std::env::args(), because this crate is aware of argument quoting, and special characteres in quotes ("*") are intentionally not expanded.

The glob syntax on Windows is limited to *, ?, and [a-z]/[!a-z] ranges, as supported by the glob crate. Parsing of quoted arguments precisely follows Windows' native syntax (CommandLineToArgvW, specifically).

Usage

wild::args() is a drop-in replacement for std::env::args().

[dependencies]
wild = "2"
fn main() {
    let args = wild::args();
    println!("The args are: {:?}", args.collect::<Vec<_>>());
}

Usage with Clap

let matches = clap::App::new("your_app")
    .arg()
    .arg()
    .arg()
    // .get_matches(); change to:
    .get_matches_from(wild::args());

Dependencies

~12KB