Split operations from other top-level args in --help
This commit is contained in:
parent
18e7154c03
commit
09f9181281
|
@ -717,10 +717,38 @@ void ArgumentParser::printHelp(ostream &os) const
|
||||||
}
|
}
|
||||||
EscapeCodes::setStyle(os);
|
EscapeCodes::setStyle(os);
|
||||||
if (!m_mainArgs.empty()) {
|
if (!m_mainArgs.empty()) {
|
||||||
os << "Available arguments:";
|
bool hasOperations = false;
|
||||||
for (const Argument *arg : m_mainArgs) {
|
for (const Argument *arg : m_mainArgs) {
|
||||||
os << '\n';
|
if (arg->denotesOperation()) {
|
||||||
arg->printInfo(os);
|
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) {
|
if (applicationUrl && *applicationUrl) {
|
||||||
|
|
|
@ -679,15 +679,16 @@ void ArgumentParserTests::testHelp()
|
||||||
const OutputCheck c("\e[1m" APP_NAME ", version " APP_VERSION "\n"
|
const OutputCheck c("\e[1m" APP_NAME ", version " APP_VERSION "\n"
|
||||||
"\e[0mLinked against: somelib, some other lib\n"
|
"\e[0mLinked against: somelib, some other lib\n"
|
||||||
"\n\e[0m"
|
"\n\e[0m"
|
||||||
"Available arguments:\n"
|
"Available operations:\n"
|
||||||
"\e[1m--help, -h\e[0m\n"
|
|
||||||
" shows this information\n"
|
|
||||||
" particularities: mandatory\n"
|
|
||||||
"\n"
|
|
||||||
"\e[1mverbose, -v\e[0m\n"
|
"\e[1mverbose, -v\e[0m\n"
|
||||||
" be verbose\n"
|
" be verbose\n"
|
||||||
" example: actually not an operation\n"
|
" example: actually not an operation\n"
|
||||||
"\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"
|
"\e[1m--files, -f\e[0m\n"
|
||||||
" specifies the path of the file(s) to be opened\n"
|
" specifies the path of the file(s) to be opened\n"
|
||||||
" \e[1m--sub\e[0m\n"
|
" \e[1m--sub\e[0m\n"
|
||||||
|
|
Loading…
Reference in New Issue