Collect parse handler args into a struct with proper names.

This commit is contained in:
2025-11-17 18:11:32 +11:00
parent a6abeff9f2
commit 4f1a01f81c
6 changed files with 44 additions and 30 deletions

View File

@@ -37,17 +37,16 @@ extern "C" fn safe_main(args: &[&str]) -> ExitCode {
// Parse command-line arguments from argv
match OPTIONS.parse(
SimplePathBuf::from(*args.first().unwrap()).basename(),
args.iter().skip(1),
|program_name, id, _opt, _name, arg| {
match id {
args.iter().skip(1), |ctx| {
match ctx.id {
Arg::Help => {
let ctx = HelpWriterContext { options: &OPTIONS, program_name };
let ctx = HelpWriterContext { options: &OPTIONS, program_name: ctx.program_name };
print!("{}", StandardFullHelpWriter::<'_, Arg>::new(ctx));
return Ok(ParseControl::Quit);
}
Arg::Number => { number = str::parse(arg)?; }
Arg::File => { file = arg.into(); }
Arg::Out => { out = Some(arg.into()); }
Arg::Number => { number = str::parse(ctx.arg)?; }
Arg::File => { file = ctx.arg.into(); }
Arg::Out => { out = Some(ctx.arg.into()); }
}
Ok(ParseControl::Continue)
}, |program_name, error| {