mirror of
https://github.com/Noratrieb/badargs.git
synced 2026-01-14 11:55:00 +01:00
readme
This commit is contained in:
parent
a393fce416
commit
c95f36d412
2 changed files with 39 additions and 0 deletions
38
README.md
38
README.md
|
|
@ -1,3 +1,41 @@
|
||||||
# badargs
|
# badargs
|
||||||
|
|
||||||
A zero-dependency full type-safe argument parser.
|
A zero-dependency full type-safe argument parser.
|
||||||
|
|
||||||
|
`badargs` handles non Utf8 input by just printing an error and exiting the program gracefully.
|
||||||
|
|
||||||
|
# How to use
|
||||||
|
|
||||||
|
```rust
|
||||||
|
use badargs::arg;
|
||||||
|
|
||||||
|
arg!(OutFile: "output", 'o' -> String);
|
||||||
|
arg!(Force: "force", 'f' -> bool);
|
||||||
|
arg!(OLevel: "optimize" -> usize);
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let args = badargs::badargs!(OutFile, Force, OLevel);
|
||||||
|
|
||||||
|
let outfile = args.get::<OutFile>();
|
||||||
|
let force = args.get::<Force>();
|
||||||
|
let o_level = args.get::<OLevel>();
|
||||||
|
|
||||||
|
println!("output: {:?}", outfile);
|
||||||
|
println!("force: {:?}", force);
|
||||||
|
println!("o-level: {:?}", o_level);
|
||||||
|
println!("other args: {:?}", args.unnamed())
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Use the `badargs::arg!` macro to declare arguments like this:
|
||||||
|
`arg!(Binding, long_name, optional_short_name -> return_type)`
|
||||||
|
|
||||||
|
The following return types are currently available:
|
||||||
|
* String
|
||||||
|
* bool
|
||||||
|
* isize
|
||||||
|
* usize
|
||||||
|
|
||||||
|
Boolean values can only be `None` or `Some`.
|
||||||
|
The other values can be `None` or `Some(_)`
|
||||||
|
|
@ -14,4 +14,5 @@ fn main() {
|
||||||
println!("output: {:?}", outfile);
|
println!("output: {:?}", outfile);
|
||||||
println!("force: {:?}", force);
|
println!("force: {:?}", force);
|
||||||
println!("o-level: {:?}", o_level);
|
println!("o-level: {:?}", o_level);
|
||||||
|
println!("other args: {:?}", args.unnamed())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue