Skip to content

Commit 06a209d

Browse files
committed
added guard toward illegal options
1 parent 3edd2d1 commit 06a209d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/main.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ int main(int argc, char **argv) {
319319
int option_index = 1;
320320
c = getopt_long(argc, argv, "-:c:d:f:j:m:o:p:h",
321321
long_options, &option_index);
322-
322+
323323
if (c == -1) // exit the loop if run out of options
324324
break;
325325

@@ -338,9 +338,16 @@ int main(int argc, char **argv) {
338338
case 0: // case for long options without short options
339339
if(strcmp(long_options[option_index].name,"search-depth") == 0)
340340
userInput.kmerDepth = atoi(optarg);
341-
if(strcmp(long_options[option_index].name,"traversal-algorithm") == 0)
341+
else if(strcmp(long_options[option_index].name,"traversal-algorithm") == 0)
342342
userInput.travAlgorithm = optarg;
343343
break;
344+
case '?': // unrecognized option
345+
if (optopt != 0)
346+
fprintf(stderr, "Unrecognized option: %c\n", optopt);
347+
else
348+
fprintf(stderr, "Unrecognized option: %s\n", argv[optind-1]);
349+
printHelp();
350+
break;
344351
case 'c': // coverage cutoff
345352
if (!isNumber(optarg)) {
346353
fprintf(stderr, "input '%s' to option -%c must be a number\n", optarg, optopt);

0 commit comments

Comments
 (0)