Closed velasco300 closed 1 week ago
I'm trying to implement subcommands with different parsers, but it appears that you can only use parseParamsComptime
once due to it hardcoding Param(Help)
in the return type.
Could you add a parseParamsComptime
variant where I can pass in an Id?
I've tried your code and it does compile fine (after changing .int = clap.parsers.int,
to .int = clap.parsers.int(u8, 10),
).
The problem now is when you do:
$ zig-out/bin/exe client
Invalid argument 'client'
What happens here, is that clap.parse
with params
succeeds and the program end up in the .client
switch case. Then clap.parse
on client_params
fails because it does not expect a positional argument, and clap.parse
looks at all arguments given to the program. I recommend having a look at the links above for examples of how people have done sub commands.
Another resource is the PR https://github.com/Hejsil/zig-clap/pull/93. There is an example for how you can use clap
to find the first positional and parse args[0..first_pos + 1]
with one parser and args[first_pos + 1..]
with another.
This is not a feature this library has yet and I've not had much motivation to implement this feature myself. It is not really a feature I need this library to have for my projects, so I've had little motivation to come up with a good API and implement it.
Here are some examples of how people have implemented subcommands and then used
zig-clap
to parse the args for each command: