From 98ff7bc396ba50c17b0afb1dfec588c1f93e4644 Mon Sep 17 00:00:00 2001 From: Federico Ponchio Date: Mon, 29 May 2017 13:51:50 +0200 Subject: [PATCH] Improved help reporting in getopt. --- wrap/system/qgetopt.cpp | 9 ++++++++- wrap/system/qgetopt.h | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/wrap/system/qgetopt.cpp b/wrap/system/qgetopt.cpp index 1e5c2892..13229982 100644 --- a/wrap/system/qgetopt.cpp +++ b/wrap/system/qgetopt.cpp @@ -173,6 +173,11 @@ QString GetOpt::usage() { } u += "]"; } + + if(unlimitedArgs) { + u += " [ARGS]"; + } + if(has_options) { u += " [-"; for(int i = 0; i < options.size(); i++) { @@ -182,6 +187,8 @@ QString GetOpt::usage() { u += "]"; } u += "\n\n"; + u += help; + u += "\n\n"; //compute maxlen: int maxlen = 0; for(int i = 0; i < options.size(); i++) { @@ -252,7 +259,7 @@ bool GetOpt::parse(QString &error) { for(int i = 0; i < args.size(); i++) { QString arg = args[i]; if(args[i] == "-h" || args[i] == "--help") { - cout << qPrintable(usage()) << endl << qPrintable(help) << endl; + cout << qPrintable(usage()) << endl; exit(0); } //long option diff --git a/wrap/system/qgetopt.h b/wrap/system/qgetopt.h index e4260fd5..9cb6c5d0 100644 --- a/wrap/system/qgetopt.h +++ b/wrap/system/qgetopt.h @@ -105,7 +105,7 @@ class GetOpt { void allowUnlimitedArguments(bool allow) { unlimitedArgs = allow; } //set help if someone uses -h or --help option - void setHelp(QString &_help) { help = _help; } + void setHelp(const QString &_help) { help = _help; } //parses the command line and fill variables or print an error message and exits void parse();