Add --help command line option

Added a simple usage text on the command line.  Also added a
--verbose alias for completeness.

Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Henrik Brautaset Aronsen 2013-05-29 13:50:38 +02:00 committed by Dirk Hohndel
parent 94baac4cf3
commit 2df3c33d5d

31
main.c
View file

@ -87,27 +87,52 @@ const char *monthname(int mon)
*/ */
static gboolean imported = FALSE; static gboolean imported = FALSE;
static void print_version() {
printf("Subsurface v%s, ", VERSION_STRING);
printf("built with libdivecomputer v%s\n", dc_version(NULL));
}
static void print_help() {
print_version();
printf("\nUsage: subsurface [options] [logfile ...] [--import logfile ...]");
printf("\n\noptions include:");
printf("\n --help|-h This help text");
printf("\n --import logfile ... Logs before this option is treated as base, everything after is imported");
printf("\n --verbose|-v Verbose debug (repeat to increase verbosity)");
printf("\n --version Prints current version\n\n");
}
static void parse_argument(const char *arg) static void parse_argument(const char *arg)
{ {
const char *p = arg+1; const char *p = arg+1;
do { do {
switch (*p) { switch (*p) {
case 'h':
print_help();
exit(0);
case 'v': case 'v':
verbose++; verbose++;
continue; continue;
case '-': case '-':
/* long options with -- */ /* long options with -- */
if (strcmp(arg,"--import") == 0) { if (strcmp(arg, "--help") == 0) {
print_help();
exit(0);
}
if (strcmp(arg, "--import") == 0) {
/* mark the dives so far as the base, /* mark the dives so far as the base,
* everything after is imported */ * everything after is imported */
process_dives(FALSE, FALSE); process_dives(FALSE, FALSE);
imported = TRUE; imported = TRUE;
return; return;
} }
if (strcmp(arg, "--verbose") == 0) {
verbose++;
return;
}
if (strcmp(arg, "--version") == 0) { if (strcmp(arg, "--version") == 0) {
printf("Subsurface v%s, ", VERSION_STRING); print_version();
printf("built with libdivecomputer v%s\n", dc_version(NULL));
exit(0); exit(0);
} }
/* fallthrough */ /* fallthrough */