[PATCH] fwts_framework: handle -? option differently from -h

Colin King colin.king at canonical.com
Fri Jan 20 11:36:49 UTC 2017


From: Colin Ian King <colin.king at canonical.com>

When optargs fail, the optarg short option '?' is returned
which currently acts the same as -h.  The result is that
the user can use an incorrect option and they get more than
a console's worth of help information and the error message
scrolls off the screen, which isn't too helpful.  Instead,
make the -? option just inform the user that there is a -h
option for more help, thus the error message from the failed
optarg scanning is not scrolled off the screen.

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 src/lib/src/fwts_framework.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c
index 2b5b094..f58db47 100644
--- a/src/lib/src/fwts_framework.c
+++ b/src/lib/src/fwts_framework.c
@@ -86,7 +86,7 @@ static fwts_list tests_to_skip;
 
 static fwts_option fwts_framework_options[] = {
 	{ "stdout-summary", 	"",   0, "Output SUCCESS or FAILED to stdout at end of tests." },
-	{ "help", 		"h?", 0, "Print this help." },
+	{ "help", 		"h?", 0, "Get help." },
 	{ "results-output", 	"r:", 1, "Output results to a named file. Filename can also be stout or stderr, e.g. --results-output=myresults.log,  -r stdout." },
 	{ "results-no-separators", "", 0, "No horizontal separators in results log." },
 	{ "log-filter", 	"",   1, "Define filters to dump out specific log fields: --log-filter=RES,SUM - dump out results and summary, --log-filter=ALL,~INF - dump out all fields except info fields." },
@@ -1344,9 +1344,11 @@ int fwts_framework_options_handler(fwts_framework *fw, int argc, char * const ar
 		fw->flags |= FWTS_FLAG_FORCE_CLEAN;
 		break;
 	case 'h':
-	case '?':
 		fwts_framework_syntax(argv);
 		return FWTS_COMPLETE;
+	case '?':
+		fprintf(stderr, "for help, use fwts -h\n");
+		return FWTS_COMPLETE;
 	case 'i': /* --interactive */
 		fw->flags |= FWTS_FLAG_INTERACTIVE;
 		break;
-- 
2.10.2




More information about the fwts-devel mailing list