Skip to content

Commit 1ee3fd3

Browse files
author
jolly_uwu
committed
fix: show short error on missing argument and unknown flag
1 parent 1d43d67 commit 1ee3fd3

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

base.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ int main(int argc, char *argv[])
678678
};
679679

680680
int c;
681-
while ((c = getopt_long(argc, argv, "i:o:I:O:X:hVx", long_opts, NULL)) != -1) {
681+
while ((c = getopt_long(argc, argv, ":i:o:I:O:X:hVx", long_opts, NULL)) != -1) {
682682
switch (c) {
683683
case 'i':
684684
if (parse_base(optarg, &ispec) != 0)
@@ -696,7 +696,8 @@ int main(int argc, char *argv[])
696696
case 'X': xor_path = optarg; break;
697697
case 'h': usage(EXIT_SUCCESS); break;
698698
case 'V': version(); break;
699-
default: usage(EXIT_FAILURE);
699+
case ':': { char o[3] = {'-', (char)optopt, '\0'}; die_fmt("option requires an argument: %s", o); break; }
700+
default: { char o[3] = {'-', (char)optopt, '\0'}; die_fmt("unknown option: %s", o); break; }
700701
}
701702
}
702703

0 commit comments

Comments
 (0)