E-MailRelay
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
G::OptionsUsage Class Reference

Provides help text for a set of options. More...

#include <goptionsusage.h>

Classes

struct  Config
 A configuration structure for G::OptionsUsage. More...
 

Public Types

using SortFn = std::function< bool(const Option &, const Option &)>
 

Public Member Functions

 OptionsUsage (const std::vector< Option > &, SortFn=sort())
 Constructor. More...
 
std::string summary (const Config &, const std::string &exe, const std::string &args={}) const
 Returns a one-line (or line-wrapped) usage summary, as "usage: <exe> <options> <args>". More...
 
std::string help (const Config &, bool *overflow_p=nullptr) const
 Returns a multi-line string giving help on each option. More...
 
void output (const Config &, std::ostream &stream, const std::string &exe, const std::string &args={}) const
 Streams out multi-line usage text using summary() and help(). More...
 

Static Public Member Functions

static SortFn sort ()
 Returns the default sort function that sorts by level first and then by name. More...
 

Detailed Description

Provides help text for a set of options.

If configured with a fixed separator the help() text is formatted as:

<margin><syntax><separator><detail-to-width1>
<margin><separator-spaces><more-detail-to-width2>

Or with a tab separator:

<margin><syntax><TAB><detail-to-width1>
<margin><TAB><more-detail-to-width2>

Or with a two-column layout:

<margin><syntax><spaces-to-column><detail-to-width1>
<margin><spaces-to-column><more-detail-to-width2>

Or two-column layout in 'overflow' mode:

<margin><syntax>
<margin><overflow-spaces><detail-to-width2>
<margin><overflow-spaces><more-detail-to-width2>

Definition at line 64 of file goptionsusage.h.

Member Typedef Documentation

◆ SortFn

using G::OptionsUsage::SortFn = std::function<bool(const Option&,const Option&)>

Definition at line 105 of file goptionsusage.h.

Constructor & Destructor Documentation

◆ OptionsUsage()

G::OptionsUsage::OptionsUsage ( const std::vector< Option > &  ,
SortFn  = sort() 
)
explicit

Constructor.

Definition at line 32 of file goptionsusage.cpp.

Member Function Documentation

◆ help()

std::string G::OptionsUsage::help ( const Config config_in,
bool *  overflow_p = nullptr 
) const

Returns a multi-line string giving help on each option.

Use the optional overflow flag if using help() for separate sections that should have the same layout: initialise to false, call help() for each section and discard the result, then call help() again for each section.

Definition at line 69 of file goptionsusage.cpp.

◆ output()

void G::OptionsUsage::output ( const Config config,
std::ostream &  stream,
const std::string &  exe,
const std::string &  args = {} 
) const

Streams out multi-line usage text using summary() and help().

Definition at line 90 of file goptionsusage.cpp.

◆ sort()

G::OptionsUsage::SortFn G::OptionsUsage::sort ( )
static

Returns the default sort function that sorts by level first and then by name.

Definition at line 288 of file goptionsusage.cpp.

◆ summary()

std::string G::OptionsUsage::summary ( const Config config_in,
const std::string &  exe,
const std::string &  args = {} 
) const

Returns a one-line (or line-wrapped) usage summary, as "usage: <exe> <options> <args>".

The 'args' parameter should represent the non-option arguments (with a leading space), like " <foo> [<bar>]".

Eg:

< std::cout << usage.summary(
< OptionsUsage::Config().set_level_max(verbose?1U:99U).set_extra(verbose) ,
< getopt.args().prefix() , " <arg> [<arg> ...]" ) << std::endl ;
<

Definition at line 49 of file goptionsusage.cpp.


The documentation for this class was generated from the following files: