It would be nice if the result of getopt would have an attribute "passedArguments" (or another name) which returns a tuple array of type (string, bool). First value is the passed argument and the seccond value indicates whether it was listed in the getopt definition.
Example:
auto helpInformation = getopt(
args,
"length", &length, // numeric
"file", &data, // string
"verbose", &verbose, // flag
"color", "Information about this color", &color);
> ./app --file "abc" --anotherOption 15
helpInformation.passedArguments would now contain an array of 2 elements
[tuple("file", true), tuple("anotherOption", false)]
Use case:
If would like to enable following console command
./app set-config --optional-value1 (true|false) --optional-value2 (true-false)
- Either optional-value1 or optinal-value2 or both must be given. Otherwise error
- Either true or false have to be specified. Otherwise error
I already found a solution but the passedArguments attribute would make the coding much more readable.
Comment #1 by robert.schadek — 2024-12-01T16:30:56Z