From 6b2618899001a93515f16820411ddfc9367f8cd7 Mon Sep 17 00:00:00 2001 From: a dinosaur Date: Sun, 2 Nov 2025 21:53:37 +1100 Subject: [PATCH] Legally mandated fancy README.md --- README.md | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/README.md b/README.md index eaaff19..0c20d41 100644 --- a/README.md +++ b/README.md @@ -1 +1,62 @@ # jaarg argument parser library # +nostd & (mostly) const, some say it can parse your arguments. + +### Obligatory fancy banners ### +
+ + Crates version + + + MIT License + +
+ +### Example usage ### +```rust +// Variables for arguments to fill +let mut file = PathBuf::new(); +let mut out: Option = None; +let mut number = 0; + +// Set up arguments table +enum Arg { Help, Number, File, Out } +const OPTIONS: Opts = Opts::new(&[ + Opt::help_flag(Arg::Help, &["-h", "--help"]).help_text("Show this help and exit."), + Opt::value(Arg::Number, &["-n", "--number"], "value").help_text("Optionally specify a number (default: 0)"), + Opt::positional(Arg::File, "file").required().help_text("Input file."), + Opt::positional(Arg::Out, "out").help_text("Output destination (optional).") +]).with_description("My simple utility."); + +// Parse the arguments +match OPTIONS.parse_easy(|program_name, id, _opt, _name, arg| { + match id { + Arg::Help => { + OPTIONS.print_full_help(program_name); + return Ok(ParseControl::Quit); + } + Arg::Number => { number = str::parse(arg)?; } + Arg::File => { file = arg.into(); } + Arg::Out => { out = Some(arg.into()); } + } + Ok(ParseControl::Continue) +}) { + ParseResult::ContinueSuccess => (), + ParseResult::ExitSuccess => std::process::exit(0), + ParseResult::ExitError => std::process::exit(1), +} + +// Print the result variables +println!("{file:?} -> {out:?} (number: {number:?})", + out = out.unwrap_or(file.with_extension("out"))); +``` + +### Changelog ### + + + +v0.1.0: + * Initial release. + +### Projects using jaarg (very cool) ### + + * [lbminfo](https://github.com/ScrelliCopter/colourcyclinginthehousetonight/tree/main/lbminfo)