Show description in --help

sendfile
Martchus 3 years ago
parent eb34ce610d
commit 780ba7bc18
  1. 37
      application/argumentparser.cpp
  2. 12
      tests/argumentparsertests.cpp

@ -786,31 +786,31 @@ void ArgumentParser::addMainArgument(Argument *argument)
void ArgumentParser::printHelp(ostream &os) const
{
EscapeCodes::setStyle(os, EscapeCodes::TextAttribute::Bold);
bool wroteLine = false;
if (applicationInfo.name && *applicationInfo.name) {
os << applicationInfo.name;
if (applicationInfo.version && *applicationInfo.version) {
os << ',' << ' ';
}
wroteLine = true;
}
if (applicationInfo.version && *applicationInfo.version) {
os << "version " << applicationInfo.version;
wroteLine = true;
}
if (applicationInfo.dependencyVersions.size()) {
if ((applicationInfo.name && *applicationInfo.name) || (applicationInfo.version && *applicationInfo.version)) {
os << '\n';
EscapeCodes::setStyle(os);
}
auto i = applicationInfo.dependencyVersions.begin(), end = applicationInfo.dependencyVersions.end();
os << "Linked against: " << *i;
for (++i; i != end; ++i) {
os << ',' << ' ' << *i;
}
}
if ((applicationInfo.name && *applicationInfo.name) || (applicationInfo.version && *applicationInfo.version)
|| applicationInfo.dependencyVersions.size()) {
if (wroteLine) {
os << '\n' << '\n';
}
EscapeCodes::setStyle(os);
if (applicationInfo.description && *applicationInfo.description) {
os << applicationInfo.description;
wroteLine = true;
}
if (wroteLine) {
os << '\n' << '\n';
}
if (!m_mainArgs.empty()) {
bool hasOperations = false;
for (const Argument *const arg : m_mainArgs) {
@ -851,6 +851,17 @@ void ArgumentParser::printHelp(ostream &os) const
}
}
}
if (!applicationInfo.dependencyVersions.empty()) {
os << '\n';
auto i = applicationInfo.dependencyVersions.begin(), end = applicationInfo.dependencyVersions.end();
os << "Linked against: " << *i;
for (++i; i != end; ++i) {
os << ',' << ' ' << *i;
}
os << '\n';
}
if (applicationInfo.url && *applicationInfo.url) {
os << "\nProject website: " << applicationInfo.url << endl;
}

@ -795,8 +795,9 @@ void ArgumentParserTests::testHelp()
const char *const argv[] = { "app", "-h" };
{
const OutputCheck c("\e[1m" APP_NAME ", version " APP_VERSION "\n"
"\e[0mLinked against: somelib, some other lib\n"
"\n\e[0m"
"\n"
"\e[0m" APP_DESCRIPTION "\n"
"\n"
"Available operations:\n"
"\e[1mverbose, -v\e[0m\n"
" be verbose\n"
@ -820,6 +821,8 @@ void ArgumentParserTests::testHelp()
" disables formatted/colorized output\n"
" default environment variable: ENABLE_ESCAPE_CODES\n"
"\n"
"Linked against: somelib, some other lib\n"
"\n"
"Project website: " APP_URL "\n");
EscapeCodes::enabled = true;
parser.parseArgs(2, argv, ParseArgumentBehavior::CheckConstraints | ParseArgumentBehavior::InvokeCallbacks);
@ -829,7 +832,8 @@ void ArgumentParserTests::testHelp()
parser.setMainArguments({ &verboseArg, &filesArg, &envArg, &parser.helpArg() });
{
const OutputCheck c(APP_NAME ", version " APP_VERSION "\n"
"Linked against: somelib, some other lib\n"
"\n"
APP_DESCRIPTION "\n"
"\n"
"Available arguments:\n"
"--verbose, -v\n"
@ -849,6 +853,8 @@ void ArgumentParserTests::testHelp()
" env\n"
" default environment variable: FILES\n"
"\n"
"Linked against: somelib, some other lib\n"
"\n"
"Project website: " APP_URL "\n");
EscapeCodes::enabled = false;
parser.resetArgs();

Loading…
Cancel
Save