wild

Crates.iowild
lib.rswild
version2.2.1
sourcesrc
created_at2017-11-17 15:22:20.056667
updated_at2024-01-27 15:57:09.341608
descriptionGlob (wildcard) expanded command-line arguments on Windows
homepagehttps://lib.rs/crates/wild
repositoryhttps://gitlab.com/kornelski/wild
max_upload_size
id39700
size27,166
maintainers (github:rust-bus:maintainers)

documentation

https://docs.rs/wild

README

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());
Commit count: 36

cargo fmt