From 27293fb53edafe1185cb1e7b97871ed2c0aafc14 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Wed, 13 Dec 2023 12:17:41 +0100 Subject: [PATCH] add completion example --- examples/completion.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 examples/completion.rs diff --git a/examples/completion.rs b/examples/completion.rs new file mode 100644 index 0000000..22679c6 --- /dev/null +++ b/examples/completion.rs @@ -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 for Settings { + fn apply(&mut self, _arg: Arg) { + panic!("Compile with the 'parse-is-complete' feature!") + } +} + +fn main() { + Settings.parse(std::env::args_os()); +}