Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generated binaries show usage when given -h/--help #8

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/match_traildb.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <getopt.h>
#include <time.h>
#include <sys/time.h>
#include <sysexits.h>

#ifdef _OPENMP
#include <omp.h>
Expand Down Expand Up @@ -1104,6 +1105,20 @@ int run_query(char **traildb_paths, int num_paths,
}


void print_usage(FILE *stream, char *progname) {

fprintf(stream,
"Usage: %s [OPTIONS] TRAILDB [TRAILDB...]\n\n",
progname);
fprintf(stream, "OPTIONS:\n");
fprintf(stream, " -p --params PARAMS\n");
fprintf(stream, " -o --output-format FORMAT\n");
fprintf(stream, " -f --filter FILTER\n");
fprintf(stream, " -w --window-file FILE\n");

}


int parse_args(int argc, char **argv,
char **params_config_file,
char **filter,
Expand All @@ -1123,6 +1138,7 @@ int parse_args(int argc, char **argv,
{"output-format", required_argument, 0, 'o' },
{"filter", required_argument, 0, 'f' },
{"window-file",required_argument, 0, 'w' },
{"help",optional_argument, 0, 'h' },
{0, 0, 0, 0 }
};

Expand All @@ -1136,6 +1152,11 @@ int parse_args(int argc, char **argv,
case 'f': *filter = optarg; break;
case 'w': *window_file = optarg; break;
case 'o': *format = optarg; break;
case '?':
case 'h':
print_usage(stderr, argv[0]);
exit(EX_USAGE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be nitpicking, but I thought EX_USAGE is intended for the case when the binary received incorrect arguments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. The case '?' clause for unhandled arguments will fall through to the case 'h'.
My thought is that invocations that result in the usage printed indicate bad arguments and explicitly asking for the usage is a special case.

break;
}
}
CHECK(optind < argc, "required: traildb path");
Expand Down Expand Up @@ -1175,8 +1196,8 @@ int main(int argc, char **argv)
&filter, &format, &window_file);

if (num_dbs == 0) {
fprintf(stderr, "usage: %s TRAILDB_PATH [groupby FIELD]\n", argv[0]);
return 1;
print_usage(stderr, argv[0]);
exit(EX_USAGE);
}

if (num_dbs > 1 && !match_no_rewind()) {
Expand Down