userspace: Fix getopt_long usage
- Add missing null entry after the last long option - Don't duplicate illegal option message, getopt already prints the message as I do not suppress it. Also handle missing arguments.
This commit is contained in:
@@ -197,6 +197,7 @@ int main(int argc, char** argv)
|
||||
{
|
||||
static option long_options[] {
|
||||
{ "help", no_argument, nullptr, 'h' },
|
||||
{}
|
||||
};
|
||||
|
||||
int ch = getopt_long(argc, argv, "h", long_options, nullptr);
|
||||
@@ -211,8 +212,7 @@ int main(int argc, char** argv)
|
||||
printf("OPTIONS:\n");
|
||||
printf(" -h, --help Show this message and exit\n");
|
||||
return 0;
|
||||
case '?':
|
||||
fprintf(stderr, "invalid option %c\n", optopt);
|
||||
case ':': case '?':
|
||||
fprintf(stderr, "see '%s --help' for usage\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user