added application info

experiment/meta_header
Martchus 7 years ago
parent 3aaed563df
commit f159952090
  1. 29
      application/argumentparser.cpp
  2. 12
      application/argumentparser.h

@ -19,6 +19,11 @@ using namespace std::placeholders;
*/
namespace ApplicationUtilities {
const char *applicationName = nullptr;
const char *applicationAuthor = nullptr;
const char *applicationVersion = nullptr;
const char *applicationUrl = nullptr;
/*!
* \class ApplicationUtilities::Argument
* \brief The Argument class is a wrapper for command line argument information.
@ -306,12 +311,26 @@ void ArgumentParser::setMainArguments(const ArgumentInitializerList &mainArgumen
*/
void ArgumentParser::printHelp(ostream &os) const
{
if(!m_mainArgs.size()) {
return;
if(applicationName && *applicationName) {
os << applicationName;
if(applicationVersion && *applicationVersion) {
os << ',' << ' ';
}
}
if(applicationVersion && *applicationVersion) {
os << "version " << applicationVersion;
}
if((applicationName && *applicationName) || (applicationVersion && *applicationVersion)) {
os << '\n' << '\n';
}
if(!m_mainArgs.empty()) {
os << "Available arguments:\n";
for(const Argument *arg : m_mainArgs) {
arg->printInfo(os);
}
}
os << "Available arguments:\n";
for(const Argument *arg : m_mainArgs) {
arg->printInfo(os);
if(applicationUrl && *applicationUrl) {
os << "\nProject website: " << applicationUrl << endl;
}
}

@ -12,8 +12,18 @@
namespace ApplicationUtilities {
class Argument;
extern const char *applicationName;
extern const char *applicationAuthor;
extern const char *applicationVersion;
extern const char *applicationUrl;
#define SET_APPLICATION_INFO \
::ApplicationUtilities::applicationName = APP_NAME; \
::ApplicationUtilities::applicationAuthor = APP_AUTHOR; \
::ApplicationUtilities::applicationVersion = APP_VERSION; \
::ApplicationUtilities::applicationUrl = APP_URL
class Argument;
class ArgumentParser;
typedef std::initializer_list<Argument *> ArgumentInitializerList;

Loading…
Cancel
Save