mirror of
https://github.com/uutils/uutils-args.git
synced 2026-06-10 16:13:08 -07:00
add completion example
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use uutils_args::{Arguments, Options, Value};
|
||||
|
||||
#[derive(Value)]
|
||||
enum Number {
|
||||
#[value]
|
||||
One,
|
||||
#[value]
|
||||
Two,
|
||||
#[value]
|
||||
Three,
|
||||
}
|
||||
|
||||
#[derive(Arguments)]
|
||||
enum Arg {
|
||||
/// Give it nothing!
|
||||
#[arg("-f", "--flag")]
|
||||
Flag,
|
||||
|
||||
// Completion is derived from the `Number` type, through the `Value` trait
|
||||
/// Give it a number!
|
||||
#[arg("-n N", "--number=N")]
|
||||
Number(Number),
|
||||
|
||||
// Completion is derived from the `PathBuf` type
|
||||
/// Give it a path!
|
||||
#[arg("-p P", "--path=P")]
|
||||
Path(PathBuf),
|
||||
}
|
||||
|
||||
struct Settings;
|
||||
|
||||
impl Options<Arg> for Settings {
|
||||
fn apply(&mut self, _arg: Arg) {
|
||||
panic!("Compile with the 'parse-is-complete' feature!")
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
Settings.parse(std::env::args_os());
|
||||
}
|
||||
Reference in New Issue
Block a user