commit 1b6b95a858b5185349db73ced93c5f08850ba369 from: Stefan Sperling date: Mon Mar 12 19:25:51 2018 UTC add -h option (help) commit - 46a0db7da03073112aca8f07035531a96ecde431 commit + 1b6b95a858b5185349db73ced93c5f08850ba369 blob - ccb72f27598eb28ba66f1e58c05bbfe0924d612e blob + 1a35ccf9fdfa3be6a333382ec6f7bc5395dd9f1d --- got/got.1 +++ got/got.1 @@ -22,6 +22,7 @@ .Sh SYNOPSIS .Nm .Ar command +.Op Fl h .Op Ar arg ... .Sh DESCRIPTION The @@ -31,6 +32,12 @@ utility is used to manage repositories. It prioritizes ease of use and simplicity over flexibility. .Pp +The options are as follows: +.Bl -tag -width tenletters +.It Fl h +Display usage information. +.El +.Pp The commands are as follows: .Bl -tag -width Ds .It Cm status blob - d426e6d04c0107315313987893f8bf4e34c4f4f6 blob + bc454f6fd980a7239121ac3fa8649e9bed111ebe --- got/got.c +++ got/got.c @@ -37,6 +37,7 @@ struct cmd { const char *cmd_name; int (*cmd_main)(int, char *[]); + void (*cmd_usage)(void); const char *cmd_descr; }; @@ -47,9 +48,11 @@ int cmd_log(int, char *[]); int cmd_status(int, char *[]); struct cmd got_commands[] = { - { "log", cmd_log, "show repository history" }, + { "log", cmd_log, usage_log, + "show repository history" }, #ifdef notyet - { "status", cmd_status, "show modification status of files" }, + { "status", cmd_status, usage_status, + "show modification status of files" }, #endif }; @@ -59,14 +62,18 @@ main(int argc, char *argv[]) struct cmd *cmd; unsigned int i; int ch; + int hflag = 0; setlocale(LC_ALL, ""); if (pledge("stdio rpath wpath cpath", NULL) == -1) err(1, "pledge"); - while ((ch = getopt(argc, argv, "")) != -1) { + while ((ch = getopt(argc, argv, "h")) != -1) { switch (ch) { + case 'h': + hflag = 1; + break; default: usage(); /* NOTREACHED */ @@ -85,6 +92,9 @@ main(int argc, char *argv[]) if (strncmp(cmd->cmd_name, argv[0], strlen(argv[0]))) continue; + if (hflag) + got_commands[i].cmd_usage(); + return got_commands[i].cmd_main(argc, argv); /* NOTREACHED */ } @@ -98,7 +108,7 @@ usage(void) { int i; - fprintf(stderr, "usage: %s command [arg ...]\n\nAvailable commands:\n", + fprintf(stderr, "usage: %s [-h] command [arg ...]\n\nAvailable commands:\n", getprogname()); for (i = 0; i < nitems(got_commands); i++) { struct cmd *cmd = &got_commands[i];