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/06/01 23:27:17 UTC

[jira] [Commented] (MESOS-2711) Add some commonly-used utility to stout/flags

    [ https://issues.apache.org/jira/browse/MESOS-2711?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14568043#comment-14568043 ] 

Marco Massenzio commented on MESOS-2711:
----------------------------------------

assigning to [~benjaminhindman] as he's going to commit the patches

> 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: Benjamin Hindman
>            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 usage(const char* argv0, const flags::FlagsBase& flags)
> {
>   cerr << "Usage: " << os::basename(argv0).get() << " [...]" << endl
>        << endl
>        << "Supported options:" << endl
>        << flags.usage();
> }
> {code}
> and in {{main.cpp}}:
> {code}
> int main(int argc, char** argv)
> {
>   bool help;
>   flags.add(&help,
>             "help",
>             "Prints this help message",
>             false);
>   // ...
>   if (load.isError()) {
>     cerr << load.error() << endl;
>     usage(argv[0], flags);
>     exit(1);
>   }
>   if (help) {
>     usage(argv[0], flags);
>     exit(1);
>   }
> }
> {code}
> Note that {{FlagsBase}} already "knows" {{argv[0]}} and it would be nice if 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)