Show description in --help
This commit is contained in:
parent
eb34ce610d
commit
780ba7bc18
|
@ -786,31 +786,31 @@ void ArgumentParser::addMainArgument(Argument *argument)
|
||||||
void ArgumentParser::printHelp(ostream &os) const
|
void ArgumentParser::printHelp(ostream &os) const
|
||||||
{
|
{
|
||||||
EscapeCodes::setStyle(os, EscapeCodes::TextAttribute::Bold);
|
EscapeCodes::setStyle(os, EscapeCodes::TextAttribute::Bold);
|
||||||
|
bool wroteLine = false;
|
||||||
if (applicationInfo.name && *applicationInfo.name) {
|
if (applicationInfo.name && *applicationInfo.name) {
|
||||||
os << applicationInfo.name;
|
os << applicationInfo.name;
|
||||||
if (applicationInfo.version && *applicationInfo.version) {
|
if (applicationInfo.version && *applicationInfo.version) {
|
||||||
os << ',' << ' ';
|
os << ',' << ' ';
|
||||||
}
|
}
|
||||||
|
wroteLine = true;
|
||||||
}
|
}
|
||||||
if (applicationInfo.version && *applicationInfo.version) {
|
if (applicationInfo.version && *applicationInfo.version) {
|
||||||
os << "version " << applicationInfo.version;
|
os << "version " << applicationInfo.version;
|
||||||
|
wroteLine = true;
|
||||||
}
|
}
|
||||||
if (applicationInfo.dependencyVersions.size()) {
|
if (wroteLine) {
|
||||||
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()) {
|
|
||||||
os << '\n' << '\n';
|
os << '\n' << '\n';
|
||||||
}
|
}
|
||||||
EscapeCodes::setStyle(os);
|
EscapeCodes::setStyle(os);
|
||||||
|
|
||||||
|
if (applicationInfo.description && *applicationInfo.description) {
|
||||||
|
os << applicationInfo.description;
|
||||||
|
wroteLine = true;
|
||||||
|
}
|
||||||
|
if (wroteLine) {
|
||||||
|
os << '\n' << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
if (!m_mainArgs.empty()) {
|
if (!m_mainArgs.empty()) {
|
||||||
bool hasOperations = false;
|
bool hasOperations = false;
|
||||||
for (const Argument *const arg : m_mainArgs) {
|
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) {
|
if (applicationInfo.url && *applicationInfo.url) {
|
||||||
os << "\nProject website: " << applicationInfo.url << endl;
|
os << "\nProject website: " << applicationInfo.url << endl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -795,8 +795,9 @@ void ArgumentParserTests::testHelp()
|
||||||
const char *const argv[] = { "app", "-h" };
|
const char *const argv[] = { "app", "-h" };
|
||||||
{
|
{
|
||||||
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"
|
"\n"
|
||||||
"\n\e[0m"
|
"\e[0m" APP_DESCRIPTION "\n"
|
||||||
|
"\n"
|
||||||
"Available operations:\n"
|
"Available operations:\n"
|
||||||
"\e[1mverbose, -v\e[0m\n"
|
"\e[1mverbose, -v\e[0m\n"
|
||||||
" be verbose\n"
|
" be verbose\n"
|
||||||
|
@ -820,6 +821,8 @@ void ArgumentParserTests::testHelp()
|
||||||
" disables formatted/colorized output\n"
|
" disables formatted/colorized output\n"
|
||||||
" default environment variable: ENABLE_ESCAPE_CODES\n"
|
" default environment variable: ENABLE_ESCAPE_CODES\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
"Linked against: somelib, some other lib\n"
|
||||||
|
"\n"
|
||||||
"Project website: " APP_URL "\n");
|
"Project website: " APP_URL "\n");
|
||||||
EscapeCodes::enabled = true;
|
EscapeCodes::enabled = true;
|
||||||
parser.parseArgs(2, argv, ParseArgumentBehavior::CheckConstraints | ParseArgumentBehavior::InvokeCallbacks);
|
parser.parseArgs(2, argv, ParseArgumentBehavior::CheckConstraints | ParseArgumentBehavior::InvokeCallbacks);
|
||||||
|
@ -829,7 +832,8 @@ void ArgumentParserTests::testHelp()
|
||||||
parser.setMainArguments({ &verboseArg, &filesArg, &envArg, &parser.helpArg() });
|
parser.setMainArguments({ &verboseArg, &filesArg, &envArg, &parser.helpArg() });
|
||||||
{
|
{
|
||||||
const OutputCheck c(APP_NAME ", version " APP_VERSION "\n"
|
const OutputCheck c(APP_NAME ", version " APP_VERSION "\n"
|
||||||
"Linked against: somelib, some other lib\n"
|
"\n"
|
||||||
|
APP_DESCRIPTION "\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Available arguments:\n"
|
"Available arguments:\n"
|
||||||
"--verbose, -v\n"
|
"--verbose, -v\n"
|
||||||
|
@ -849,6 +853,8 @@ void ArgumentParserTests::testHelp()
|
||||||
" env\n"
|
" env\n"
|
||||||
" default environment variable: FILES\n"
|
" default environment variable: FILES\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
"Linked against: somelib, some other lib\n"
|
||||||
|
"\n"
|
||||||
"Project website: " APP_URL "\n");
|
"Project website: " APP_URL "\n");
|
||||||
EscapeCodes::enabled = false;
|
EscapeCodes::enabled = false;
|
||||||
parser.resetArgs();
|
parser.resetArgs();
|
||||||
|
|
Loading…
Reference in New Issue