immargs - Immediate Arguments
No-hassle, on-the-spot, command line argument parsing for Rust
Highlights:
- Straightforward declaration of arguments with proc-macro.
- Supports POSIX / GNU argument syntax conventions.
- Supports arguments of any type that implements
FromStr+Debug. - Supports (sub)commands, with aliases.
- Supports declaration of conflicting arguments.
- Supports automatic
--versionand--helphandling, with possibility to opt-out. - Tested on Linux, macOS and Windows.
- No run-time dependencies.
Basic Example
Using args_from_env! for on-the-spot declaration and parsing of command line
arguments. Returns an anonymous struct with fields corresponding to the declared
arguments.
use args_from_env;
let args = args_from_env! ;
// Assuming this program was executed with "myprog -l 3 Src0 Src1 Dest"
assert!;
assert!;
assert!;
assert!;
assert!;
assert!;
Advanced Example
Using args! to declare command line arguments.
use args;
args!
args!
args!
args!
Command Line Argument Syntax
The following POSIX / GNU argument syntax conventions are supported:
- Short option,
-followed by a single character, e.g.-f. - Long option,
--followed by two or more characters, e.g.--foo. - Short/Long option with separate value, e.g.
-f 100or--foo 100. - Short/Long option with attached value delimited by
=, e.g.-f=100or--foo=100. - Short option with attached value without delimiter, e.g.
-f100. - Combined short options, e.g.
-abcis equivalent to-a -b -c. - Short/Long options may appear in any order, but must come before any non-option arguments.
- Short/Long options may appear multiple times, the last appearance takes precedence unless
it's a variadic (repeatable) option, where the number of times the option appears has
meaning, e.g.
-vvvwhere each-vincreases the verbosity level. - The order of non-option arguments carries meaning.
- A standalone
-argument is treated as a non-option argument. - A standalone
--argument marks the end of options. Any following arguments are treated as non-option arguments.
License
Licensed under either of
at your option.
Contribution
Any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.