Skip to content

Commit 0325f2d

Browse files
committed
fix #562: support OPTIONAL_ARGUMENT
1 parent 7330097 commit 0325f2d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

base/hmain.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ int parse_opt_long(int argc, char** argv, const option_t* long_options, int size
316316
if (pOption->arg_type == NO_ARGUMENT) {
317317
// -h
318318
value = OPTION_ENABLE;
319-
} else if (pOption->arg_type == REQUIRED_ARGUMENT) {
319+
} else {
320320
if (delim) {
321321
// --port=80
322322
value = delim+1;
@@ -327,9 +327,12 @@ int parse_opt_long(int argc, char** argv, const option_t* long_options, int size
327327
} else if (argv[i+1] != NULL) {
328328
// --port 80
329329
value = argv[++i];
330-
} else {
330+
} else if (pOption->arg_type == REQUIRED_ARGUMENT) {
331331
printf("Option '%s' requires parament\n", opt);
332332
return -20;
333+
} else {
334+
// arg_type == OPTIONAL_ARGUMENT
335+
value = OPTION_ENABLE;
333336
}
334337
}
335338
}

0 commit comments

Comments
 (0)