2023-12-07 16:30:16 +01:00
|
|
|
use uutils_args::{Arguments, Options, Value};
|
|
|
|
|
|
|
|
|
|
#[derive(Arguments)]
|
|
|
|
|
#[arguments(file = "examples/hello_world_help.md")]
|
|
|
|
|
enum Arg {
|
|
|
|
|
/// Color!
|
|
|
|
|
#[arg("-c NAME", "--color=NAME")]
|
|
|
|
|
Color(Color),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Value, Debug, Default)]
|
|
|
|
|
enum Color {
|
|
|
|
|
#[value("never")]
|
|
|
|
|
Never,
|
|
|
|
|
#[default]
|
|
|
|
|
#[value("auto")]
|
|
|
|
|
Auto,
|
|
|
|
|
#[value("always")]
|
|
|
|
|
Always,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
|
struct Settings {
|
|
|
|
|
color: Color,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Options<Arg> for Settings {
|
2024-03-29 03:32:30 +01:00
|
|
|
fn apply(&mut self, arg: Arg) -> Result<(), uutils_args::Error> {
|
2023-12-07 16:30:16 +01:00
|
|
|
match arg {
|
|
|
|
|
Arg::Color(c) => self.color = c,
|
|
|
|
|
}
|
2024-03-29 03:32:30 +01:00
|
|
|
Ok(())
|
2023-12-07 16:30:16 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn main() {
|
2023-12-19 15:13:12 +01:00
|
|
|
let (settings, _operands) = Settings::default().parse(std::env::args_os()).unwrap();
|
2023-12-14 12:28:24 +01:00
|
|
|
println!("{:?}", settings.color);
|
2023-12-07 16:30:16 +01:00
|
|
|
}
|