zig-clap
zig-clap copied to clipboard
Support default values for short and long parameters
It's a very minor nitpick, but I found myself trying to communicate to the user the default values of different parameters in their descriptions, and then reusing those same values when parsing:
const PARAMS = clap.parseParamsComptime(
\\-o, --opt <u8> Optional argument (default: 3)
\\
);
pub fn main() !void {
...
const opt_arg = cli.args.opt orelse 3;
...
}
It's not very error-prone as is, since default values don't usually change much, but it would be nicer to have a way of specifying default values and having them parsed automatically.
Yea, that does seem worth while. I'm not sure it is something I'll really get to doing as I'm not using zig-clap that much myself anymore.
What are you using then? If I may ask
What are you using then? If I may ask
Currently, I'm testing out something simpler:
https://github.com/Hejsil/dipm/blob/4b24131e2b010ef8577fb650ca39d2305e6b3b4e/src/ArgParser.zig Usage: https://github.com/Hejsil/dipm/blob/4b24131e2b010ef8577fb650ca39d2305e6b3b4e/src/main.zig#L125
I just have a copy of this file in a few projects
Btw, I've rewritten structopt to support ZON-like structs, no fancy parser, but pretty nice to use (will be even nicer after we're able to import ZON files without result types):
https://codeberg.org/tensorush/argzon