Provides CLI argument parsing (WIP).
use facet_pretty::FacetPretty;
use facet::Facet;
#[derive(Facet)]
struct Args {
#[facet(positional)]
path: String,
#[facet(named, short = 'v')]
verbose: bool,
#[facet(named, short = 'j')]
concurrency: usize,
}
# fn main() -> Result<(), Box<dyn std::error::Error>> {
let args: Args = facet_args::from_slice(&["--verbose", "-j", "14", "example.rs"])?;
eprintln!("args: {}", args.pretty());
Ok(())
# }The behavior of facet-args is still in flux, but here are the broad strokes:
- We're always parsing to a struct (not an enum, vec etc.)
- The struct we're parsing to is always owned — no borrowing happening here, it
gets too complicated with
&'slice [&'text str] - Arguments are either
positionalornamed— fields lacking either annotation are ignored - Accepted syntaxes for short flags are:
short = 'v'andshort = "v"(where v can be any letter) positionalargs of typeVec(or anything that has aDef::List) will soak up all the positional arguments — if followed bypositionalarguments of typeStringfor example, those will never get filled- After parsing every available argument, uninitialized struct fields are filled with their default value
if they have
facet(default)set: this includesVec.
Thanks to all individual sponsors:
...along with corporate sponsors:
...without whom this work could not exist.
The facet logo was drawn by Misiasart.
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.