Improved help reporting in getopt.
This commit is contained in:
parent
0ea869a843
commit
98ff7bc396
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue