[PATCH libinput 04/11] tools: tidy up the usage() for the tools a bit

Peter Hutterer peter.hutterer at who-t.net
Sun May 28 22:47:57 UTC 2017


Now that the debug-gui is a user-visible tool, make sure the usage reflects
the right command name.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 tools/libinput-debug-events.c |  2 +-
 tools/libinput-debug-gui.c    |  2 +-
 tools/shared.c                | 38 +++++++++++++++++++++-----------------
 tools/shared.h                |  7 +++++--
 4 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/tools/libinput-debug-events.c b/tools/libinput-debug-events.c
index cf29dab5..abba707f 100644
--- a/tools/libinput-debug-events.c
+++ b/tools/libinput-debug-events.c
@@ -907,7 +907,7 @@ main(int argc, char **argv)
 
 	tools_init_context(&context);
 
-	if (tools_parse_args(argc, argv, &context))
+	if (tools_parse_args("debug-events", argc, argv, &context))
 		return 1;
 
 	be_quiet = context.options.quiet;
diff --git a/tools/libinput-debug-gui.c b/tools/libinput-debug-gui.c
index fa685275..4091b556 100644
--- a/tools/libinput-debug-gui.c
+++ b/tools/libinput-debug-gui.c
@@ -877,7 +877,7 @@ main(int argc, char **argv)
 
 	tools_init_context(&context);
 
-	if (tools_parse_args(argc, argv, &context) != 0)
+	if (tools_parse_args("debug-gui", argc, argv, &context) != 0)
 		return 1;
 
 	udev = udev_new();
diff --git a/tools/shared.c b/tools/shared.c
index bdbf8207..fef97477 100644
--- a/tools/shared.c
+++ b/tools/shared.c
@@ -93,9 +93,10 @@ log_handler(struct libinput *li,
 }
 
 void
-tools_usage(void)
+tools_usage(const char *command)
 {
-	printf("Usage: libinput debug-events [options] [--udev [<seat>]|--device /dev/input/event0]\n");
+	printf("Usage: libinput %s [options] [--udev [<seat>]|--device /dev/input/event0]\n",
+	       command);
 	printf("--udev <seat>.... Use udev device discovery (default).\n"
 	       "		  Specifying a seat ID is optional.\n"
 	       "--device /path/to/device .... open the given device only\n"
@@ -160,7 +161,10 @@ tools_init_context(struct tools_context *context)
 }
 
 int
-tools_parse_args(int argc, char **argv, struct tools_context *context)
+tools_parse_args(const char *command,
+		 int argc,
+		 char **argv,
+		 struct tools_context *context)
 {
 	struct tools_options *options = &context->options;
 
@@ -205,12 +209,12 @@ tools_parse_args(int argc, char **argv, struct tools_context *context)
 		switch(c) {
 		case 'h':
 		case OPT_HELP:
-			tools_usage();
+			tools_usage(command);
 			exit(0);
 		case OPT_DEVICE:
 			options->backend = BACKEND_DEVICE;
 			if (!optarg) {
-				tools_usage();
+				tools_usage(command);
 				return 1;
 			}
 			options->device = optarg;
@@ -234,7 +238,7 @@ tools_parse_args(int argc, char **argv, struct tools_context *context)
 			break;
 		case OPT_TAP_MAP:
 			if (!optarg) {
-				tools_usage();
+				tools_usage(command);
 				return 1;
 			}
 			if (streq(optarg, "lrm")) {
@@ -242,7 +246,7 @@ tools_parse_args(int argc, char **argv, struct tools_context *context)
 			} else if (streq(optarg, "lmr")) {
 				options->tap_map = LIBINPUT_CONFIG_TAP_MAP_LMR;
 			} else {
-				tools_usage();
+				tools_usage(command);
 				return 1;
 			}
 			break;
@@ -284,7 +288,7 @@ tools_parse_args(int argc, char **argv, struct tools_context *context)
 			break;
 		case OPT_CLICK_METHOD:
 			if (!optarg) {
-				tools_usage();
+				tools_usage(command);
 				return 1;
 			}
 			if (streq(optarg, "none")) {
@@ -297,13 +301,13 @@ tools_parse_args(int argc, char **argv, struct tools_context *context)
 				options->click_method =
 				LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
 			} else {
-				tools_usage();
+				tools_usage(command);
 				return 1;
 			}
 			break;
 		case OPT_SCROLL_METHOD:
 			if (!optarg) {
-				tools_usage();
+				tools_usage(command);
 				return 1;
 			}
 			if (streq(optarg, "none")) {
@@ -319,13 +323,13 @@ tools_parse_args(int argc, char **argv, struct tools_context *context)
 				options->scroll_method =
 				LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
 			} else {
-				tools_usage();
+				tools_usage(command);
 				return 1;
 			}
 			break;
 		case OPT_SCROLL_BUTTON:
 			if (!optarg) {
-				tools_usage();
+				tools_usage(command);
 				return 1;
 			}
 			options->scroll_button =
@@ -340,14 +344,14 @@ tools_parse_args(int argc, char **argv, struct tools_context *context)
 			break;
 		case OPT_SPEED:
 			if (!optarg) {
-				tools_usage();
+				tools_usage(command);
 				return 1;
 			}
 			options->speed = atof(optarg);
 			break;
 		case OPT_PROFILE:
 			if (!optarg) {
-				tools_usage();
+				tools_usage(command);
 				return 1;
 			}
 			if (streq(optarg, "adaptive")) {
@@ -355,7 +359,7 @@ tools_parse_args(int argc, char **argv, struct tools_context *context)
 			} else if (streq(optarg, "flat")) {
 				options->profile = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT;
 			} else {
-				tools_usage();
+				tools_usage(command);
 				return 1;
 			}
 			break;
@@ -366,14 +370,14 @@ tools_parse_args(int argc, char **argv, struct tools_context *context)
 			options->quiet = true;
 			break;
 		default:
-			tools_usage();
+			tools_usage(command);
 			return 1;
 		}
 
 	}
 
 	if (optind < argc) {
-		tools_usage();
+		tools_usage(command);
 		return 1;
 	}
 
diff --git a/tools/shared.h b/tools/shared.h
index f3a10db9..4d6e700e 100644
--- a/tools/shared.h
+++ b/tools/shared.h
@@ -65,10 +65,13 @@ struct tools_context {
 };
 
 void tools_init_context(struct tools_context *context);
-int tools_parse_args(int argc, char **argv, struct tools_context *context);
+int tools_parse_args(const char *command,
+		     int argc,
+		     char **argv,
+		     struct tools_context *context);
 struct libinput* tools_open_backend(struct tools_context *context);
 void tools_device_apply_config(struct libinput_device *device,
 			       struct tools_options *options);
-void tools_usage(void);
+void tools_usage(const char *command);
 
 #endif
-- 
2.13.0



More information about the wayland-devel mailing list