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

This commit is contained in:
Martchus 2018-01-28 00:38:05 +01:00
parent 18e7154c03
commit 09f9181281
2 changed files with 37 additions and 8 deletions

View File

@ -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) {

View File

@ -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"