Skip to content

Commit

Permalink
fix #562: support OPTIONAL_ARGUMENT
Browse files Browse the repository at this point in the history
  • Loading branch information
ithewei committed Jun 18, 2024
1 parent 7330097 commit 0325f2d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions base/hmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ int parse_opt_long(int argc, char** argv, const option_t* long_options, int size
if (pOption->arg_type == NO_ARGUMENT) {
// -h
value = OPTION_ENABLE;
} else if (pOption->arg_type == REQUIRED_ARGUMENT) {
} else {
if (delim) {
// --port=80
value = delim+1;
Expand All @@ -327,9 +327,12 @@ int parse_opt_long(int argc, char** argv, const option_t* long_options, int size
} else if (argv[i+1] != NULL) {
// --port 80
value = argv[++i];
} else {
} else if (pOption->arg_type == REQUIRED_ARGUMENT) {
printf("Option '%s' requires parament\n", opt);
return -20;
} else {
// arg_type == OPTIONAL_ARGUMENT
value = OPTION_ENABLE;
}
}
}
Expand Down

0 comments on commit 0325f2d

Please sign in to comment.