Skip to content

Commit

Permalink
provide access to usage string from command line class
Browse files Browse the repository at this point in the history
changed Tester::options() to a static member function
added CommandLine::m_usage member variable to hold usage string
added CommandLine::usage() access function
the usage string is now created at the beginning of the contructor
  • Loading branch information
thunder422 committed Dec 9, 2012
1 parent 5431b8f commit 3b93360
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
12 changes: 7 additions & 5 deletions commandline.cpp
Expand Up @@ -46,6 +46,12 @@ CommandLine::CommandLine(const QStringList &args)
m_returnCode = -1;
// NOTE: leave m_returnCode set to -1 to start GUI,

// create usage string
QStringList options = Tester::options();
// append any other options here
options.prepend("-h|-?|-v");
m_usage = tr("usage: %1 %2").arg(m_programName).arg(options.join("|"));

// parse command line arguments
if (isVersionOption(args))
{
Expand Down Expand Up @@ -76,12 +82,8 @@ CommandLine::CommandLine(const QStringList &args)
}

// unsupported option (NOTE: other options get checked before this)
QStringList options = tester.options();
// append any other options here
options.prepend("-h|-?|-v");
m_returnCode = isHelpOption(args) ? 0 : 1; // error if not help option
cout(m_returnCode == 0 ? stdout : stderr) << tr("usage: ") << m_programName
<< options.join("|") << endl;
cout(m_returnCode == 0 ? stdout : stderr) << m_usage << endl;
}


Expand Down
5 changes: 5 additions & 0 deletions commandline.h
Expand Up @@ -43,6 +43,7 @@ class CommandLine
QString m_programName;
int m_returnCode;
QTextStream m_cout;
QString m_usage;
public:
CommandLine(const QStringList &args);
~CommandLine();
Expand All @@ -59,6 +60,10 @@ class CommandLine
{
return m_programName;
}
QString usage(void) const
{
return m_usage;
}
QString version(void) const;
int copyrightYear(void) const;
static const char **gplStatement(void)
Expand Down
2 changes: 1 addition & 1 deletion test_ibcp.cpp
Expand Up @@ -114,7 +114,7 @@ bool Tester::isOption(const QString &arg, const QString &exp,


// function to return list of valid options
QStringList Tester::options(void) const
QStringList Tester::options(void)
{
return QStringList() << QString("-t <%1>").arg(tr("test_file")) << "-tp"
<< "-te" << "-tt";
Expand Down
2 changes: 1 addition & 1 deletion test_ibcp.h
Expand Up @@ -67,7 +67,7 @@ class Tester
Tester(const QStringList &args);
~Tester(void) {}

QStringList options(void) const;
static QStringList options(void);
bool run(QTextStream &cout, CommandLine *commandLine);
bool hasOption(void) const // has a test option been specified?
{
Expand Down

0 comments on commit 3b93360

Please sign in to comment.