You've already forked uutils-args
mirror of
https://github.com/uutils/uutils-args.git
synced 2026-06-10 16:13:08 -07:00
36 lines
804 B
Rust
36 lines
804 B
Rust
use uutils_args::{Arguments, Options};
|
|
|
|
#[derive(Clone, Arguments)]
|
|
#[help("--help", file = "examples/hello_world_help.md")]
|
|
#[version("--version")]
|
|
enum Arg {
|
|
/// The *name* to **greet**
|
|
///
|
|
/// Just to show off, I can do multiple paragraphs and wrap text!
|
|
///
|
|
/// # Also headings!
|
|
#[option("-n NAME", "--name=NAME")]
|
|
Name(String),
|
|
|
|
/// The **number of times** to `greet`
|
|
#[option("-c N", "--count=N")]
|
|
Count(u8),
|
|
}
|
|
|
|
#[derive(Default, Options)]
|
|
#[arg_type(Arg)]
|
|
struct Settings {
|
|
#[set(Arg::Name)]
|
|
name: String,
|
|
#[set(Arg::Count)]
|
|
count: u8,
|
|
}
|
|
|
|
fn main() -> Result<(), uutils_args::Error> {
|
|
let settings = Settings::parse(std::env::args_os());
|
|
for _ in 0..settings.count {
|
|
println!("Hello, {}!", settings.name);
|
|
}
|
|
Ok(())
|
|
}
|