nodakai
February 11, 2025, 3:43am
1
I'm trying to configure my CLI to handle the following command: cmd foo.txt bar.txt --sort
as if the user had typed cmd foo.txt bar.txt --sort=100
A GitHub issue led me to this method in the clap
API:
However, I'm struggling to get it working with the derive API.
error: a value is required for '--sort ' but none was supplied
Any help would be greatly appreciated!
NOTE: using this configuration option requires the use of the .num_args(0..N) and the .require_equals(true) configuration option. These are required in order to unambiguously determine what, if any, value was supplied for the argument.
From your linked documentation
But I get a panic when trying to follow that note:
Arg::is_takes_value_set is required when Arg::is_require_equals_set is set
Can't find the solution to that, someone with more up to date clap experience might recognise the problem
nodakai
February 11, 2025, 10:47am
4
Thanks for pointing that out. I think I figured out how to use the API.
(Unfortunate to see yet another real-world example of challenges hindering type-safe API design, but that's a discussion for another time)