Commit e5278f70 by Yoney Committed by Patrick Steinhardt

clar: verify command line arguments before execute

When executing `libgit2_clar -smerge -invalid_option`, it will first execute
the merge test suite and afterwards output help because of the invalid option.

With this changa, it verifies all options before execute. If there are any
invalid options, it will output help and exit without actually executing
the test suites.

(cherry picked from commit 32758631)
parent 306ffba3
......@@ -313,11 +313,18 @@ clar_parse_args(int argc, char **argv)
{
int i;
/* Verify options before execute */
for (i = 1; i < argc; ++i) {
char *argument = argv[i];
if (argument[0] != '-')
if (argument[0] != '-' || argument[1] == '\0'
|| strchr("sixvqQl", argument[1]) == NULL) {
clar_usage(argv[0]);
}
}
for (i = 1; i < argc; ++i) {
char *argument = argv[i];
switch (argument[1]) {
case 's':
......@@ -391,7 +398,7 @@ clar_parse_args(int argc, char **argv)
break;
default:
clar_usage(argv[0]);
assert(!"Unexpected commandline argument!");
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment