You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@mesos.apache.org by "Marco Massenzio (JIRA)" <ji...@apache.org> on 2015/05/09 04:53:59 UTC
[jira] [Created] (MESOS-2711) Add some commonly-used utility to
stout/flags
Marco Massenzio created MESOS-2711:
--------------------------------------
Summary: Add some commonly-used utility to stout/flags
Key: MESOS-2711
URL: https://issues.apache.org/jira/browse/MESOS-2711
Project: Mesos
Issue Type: Improvement
Components: stout
Affects Versions: 0.22.0
Reporter: Marco Massenzio
Assignee: Marco Massenzio
Priority: Minor
When using {{stout/flags/flags.hpp}} and implementing our own {{Flags}} class (derived from {{flags::FlagsBase}}) pretty much everyone ends up re-implementing some variant of the following:
{code}
void printUsage(const string& prog, const string& flags)
{
cout << "Usage: " << os::basename(prog).get() << " [options]\n\n"
"One (and only one) of the following options MUST be present.\n\n"
"Options:\n" << flags << endl;
}
{code}
and in {{main.cpp}}:
{code}
int main(int argc, char** argv)
{
MyFlags flags;
bool help;
flags.add(&help, "help", "Prints this help message", false);
Try<Nothing> load = flags.load(None(), argc, argv);
// ...
if (help) {
printUsage(argv[0], flags.usage());
}
// ...
}
{code}
Note that {{FlagsBase}} already "knows" {{argv[0]}} and it would be nice it implemented the "help" functionality itself, so that everyone immediately gains access to it; further, the {{printUsage()}} method could be implemented easily by simply adding the facility for derived classes to specify some form of a "blurb" (the bit that is emitted between the {{Usage:}} line and the {{Options:}} body and, possibly, to customize the "usage" one-liner.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)