winpr/utils: allow COMMAND_LINE_VALUE_{OPTIONAL,BOOL} to coexist.

Now you can give an option the combination of flags
COMMAND_LINE_VALUE_OPTIONAL and COMMAND_LINE_VALUE_BOOL. If you do,
then all three of the syntaxes +foo, -foo and /foo:value are allowed
at once, and the receiving code can tell the difference because the
Value field is set to BoolValueTrue, BoolValueFalse or a valid char
pointer.
This commit is contained in:
Simon Tatham 2020-03-18 21:00:06 +00:00 committed by akallabeth
parent 3c104d9b9b
commit c90479c7f5
2 changed files with 4 additions and 2 deletions

View File

@ -244,7 +244,8 @@ int main(int argc, char* argv[])
if (text)
fprintf(fp, "%s", text);
if (arg->Flags == COMMAND_LINE_VALUE_BOOL)
if (arg->Flags & COMMAND_LINE_VALUE_BOOL &&
(!arg->Default || arg->Default == BoolValueTrue))
fprintf(fp, " (default:%s)", arg->Default ? "on" : "off");
else if (arg->Default)
{

View File

@ -312,7 +312,8 @@ int CommandLineParseArgumentsA(int argc, LPSTR* argv, COMMAND_LINE_ARGUMENT_A* o
if (value)
{
if (options[j].Flags & (COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_VALUE_BOOL))
if (!(options[j].Flags &
(COMMAND_LINE_VALUE_OPTIONAL | COMMAND_LINE_VALUE_REQUIRED)))
{
log_error(flags, "Failed at index %d [%s]: Unexpected value", i, argv[i]);
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;