[PATCH] Add --help command line option

subsurface at henrik.synth.no subsurface at henrik.synth.no
Wed May 29 04:50:38 PDT 2013


From: Henrik Brautaset Aronsen <subsurface at henrik.synth.no>

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

Signed-off-by: Henrik Brautaset Aronsen <subsurface at henrik.synth.no>
---
 main.c | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/main.c b/main.c
index 9afaa3d..ced3ad5 100644
--- a/main.c
+++ b/main.c
@@ -82,27 +82,52 @@ const char *monthname(int mon)
  */
 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)
 {
 	const char *p = arg+1;
 
 	do {
 		switch (*p) {
+		case 'h':
+			print_help();
+			exit(0);
 		case 'v':
 			verbose++;
 			continue;
 		case '-':
 			/* 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,
 				 * everything after is imported */
 				process_dives(FALSE, FALSE);
 				imported = TRUE;
 				return;
 			}
+			if (strcmp(arg, "--verbose") == 0) {
+				verbose++;
+				return;
+			}
 			if (strcmp(arg, "--version") == 0) {
-				printf("Subsurface v%s, ", VERSION_STRING);
-				printf("built with libdivecomputer v%s\n", dc_version(NULL));
+				print_version();
 				exit(0);
 			}
 			/* fallthrough */
-- 
1.8.2.2



More information about the subsurface mailing list