Browse Source

Split operations from other top-level args in --help

improve/error-messages
Martchus 4 years ago
parent
commit
09f9181281
  1. 34
      application/argumentparser.cpp
  2. 11
      tests/argumentparsertests.cpp

34
application/argumentparser.cpp

@ -717,10 +717,38 @@ void ArgumentParser::printHelp(ostream &os) const
}
EscapeCodes::setStyle(os);
if (!m_mainArgs.empty()) {
os << "Available arguments:";
bool hasOperations = false;
for (const Argument *arg : m_mainArgs) {
os << '\n';
arg->printInfo(os);
if (arg->denotesOperation()) {
hasOperations = true;
break;
}
}
// check whether operations are available
if (hasOperations) {
// split top-level operations and other configurations
os << "Available operations:";
for (const Argument *arg : m_mainArgs) {
if (arg->denotesOperation()) {
os << '\n';
arg->printInfo(os);
}
}
os << "\nAvailable top-level options:";
for (const Argument *arg : m_mainArgs) {
if (!arg->denotesOperation()) {
os << '\n';
arg->printInfo(os);
}
}
} else {
// just show all args if no operations are available
os << "Available arguments:";
for (const Argument *arg : m_mainArgs) {
os << '\n';
arg->printInfo(os);
}
}
}
if (applicationUrl && *applicationUrl) {

11
tests/argumentparsertests.cpp

@ -679,15 +679,16 @@ void ArgumentParserTests::testHelp()
const OutputCheck c("\e[1m" APP_NAME ", version " APP_VERSION "\n"
"\e[0mLinked against: somelib, some other lib\n"
"\n\e[0m"
"Available arguments:\n"
"\e[1m--help, -h\e[0m\n"
" shows this information\n"
" particularities: mandatory\n"
"\n"
"Available operations:\n"
"\e[1mverbose, -v\e[0m\n"
" be verbose\n"
" example: actually not an operation\n"
"\n"
"Available top-level options:\n"
"\e[1m--help, -h\e[0m\n"
" shows this information\n"
" particularities: mandatory\n"
"\n"
"\e[1m--files, -f\e[0m\n"
" specifies the path of the file(s) to be opened\n"
" \e[1m--sub\e[0m\n"

Loading…
Cancel
Save