#glob #windows #shell #wildcards #CommandLineToArgvW

wild

Glob (wildcard) expanded command-line arguments on Windows

9 releases (stable)

2.0.2 Jul 21, 2019
2.0.1 Sep 3, 2018
1.1.1 Sep 3, 2018
1.1.0 Aug 31, 2018
0.1.0 Nov 17, 2017

#25 in Command-line interface

Download history 890/week @ 2019-11-10 1147/week @ 2019-11-17 1353/week @ 2019-11-24 2288/week @ 2019-12-01 1538/week @ 2019-12-08 1415/week @ 2019-12-15 1229/week @ 2019-12-22 1941/week @ 2019-12-29 1604/week @ 2020-01-05 967/week @ 2020-01-12 1034/week @ 2020-01-19 1798/week @ 2020-01-26 1698/week @ 2020-02-02 1704/week @ 2020-02-09 949/week @ 2020-02-16

5,592 downloads per month
Used in 10 crates (7 directly)

MIT license

22KB
411 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().

extern crate wild;

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

~13KB