Commit 46a0db7da03073112aca8f07035531a96ecde431

Stefan Sperling 2018-03-12T20:16:21

show a list of commands in usage()

diff --git a/got/got.c b/got/got.c
index c6d31fe..d426e6d 100644
--- a/got/got.c
+++ b/got/got.c
@@ -37,6 +37,7 @@
 struct cmd {
 	const char	 *cmd_name;
 	int		(*cmd_main)(int, char *[]);
+	const char	 *cmd_descr;
 };
 
 __dead void	usage(void);
@@ -46,9 +47,9 @@ int		cmd_log(int, char *[]);
 int		cmd_status(int, char *[]);
 
 struct cmd got_commands[] = {
-	{ "log",	cmd_log },
+	{ "log",	cmd_log,	"show repository history" },
 #ifdef notyet
-	{ "status",	cmd_status },
+	{ "status",	cmd_status,	"show modification status of files" },
 #endif
 };
 
@@ -95,7 +96,14 @@ main(int argc, char *argv[])
 __dead void
 usage(void)
 {
-	fprintf(stderr, "usage: %s command [arg ...]\n", getprogname());
+	int i;
+
+	fprintf(stderr, "usage: %s command [arg ...]\n\nAvailable commands:\n",
+	    getprogname());
+	for (i = 0; i < nitems(got_commands); i++) {
+		struct cmd *cmd = &got_commands[i];
+		fprintf(stderr, "    %s: %s\n", cmd->cmd_name, cmd->cmd_descr);
+	}
 	exit(1);
 }