From 22993290d75bacb33c177be8ee2bc78ea0687ac8 Mon Sep 17 00:00:00 2001
From: Stef Walter <stefw@gnome.org>
Date: Mon, 11 Mar 2013 09:50:38 +0100
Subject: tools: Display per-command help appropriately

 * Fixes a regression
 * In addition allows --help to be specified before the command. If
   a command is present, command help will be shown

https://bugs.freedesktop.org/show_bug.cgi?id=62153
---
 tools/tool.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

(limited to 'tools')

diff --git a/tools/tool.c b/tools/tool.c
index e9c10a0..fa68eed 100644
--- a/tools/tool.c
+++ b/tools/tool.c
@@ -229,6 +229,7 @@ int
 main (int argc, char *argv[])
 {
 	char *command = NULL;
+	bool want_help = false;
 	bool skip;
 	int in, out;
 	int i;
@@ -267,8 +268,7 @@ main (int argc, char *argv[])
 				quiet_arg ();
 
 			} else if (strcmp (argv[in], "--help") == 0) {
-				command_usage ();
-				return 0;
+				want_help = true;
 
 			} else if (!command) {
 				p11_message ("unknown global option: %s", argv[in]);
@@ -282,8 +282,8 @@ main (int argc, char *argv[])
 			for (i = 1; argv[in][i] != '\0'; i++) {
 				switch (argv[in][i]) {
 				case 'h':
-					command_usage ();
-					return 0;
+					want_help = true;
+					break;
 
 				/* Compatibility option */
 				case 'l':
@@ -320,11 +320,16 @@ main (int argc, char *argv[])
 
 	if (command == NULL) {
 		/* As a special favor if someone just typed 'p11-kit', help them out */
-		if (argc == 1)
+		if (argc == 1) {
 			command_usage ();
-		else
+			return 2;
+		} else if (want_help) {
+			command_usage ();
+			return 0;
+		} else {
 			p11_message ("no command specified");
-		return 2;
+			return 2;
+		}
 	}
 
 	argc = out;
-- 
cgit v1.1