All Classes Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
gears::optparse::formatter Struct Reference

A class that handles the formatting of the help message. More...

Public Member Functions

 formatter (size_t column=80)
 Constructs a formatter with a column defaulting to 80.
 
virtual ~formatter ()=default
 Virtual destructor.
 
virtual std::string wrap (const std::string &str, size_t indent=0)
 Wraps a string at the column point. More...
 
virtual std::string usage (const std::string &name, const std::string &command, const std::string &str)
 Handles the usage message. More...
 
virtual std::string description (const std::string &str)
 Handles the description message. More...
 
virtual std::string epilogue (const std::string &str)
 Handles the epilogue message. More...
 
virtual std::string subcommands (const std::vector< subcommand > &subs)
 Handles the list of subcommands. More...
 
virtual std::string options (const option_set &opts)
 Handles the list of options. More...
 

Public Attributes

size_t column
 The maximum column before wrap around.
 

Detailed Description

A class that handles the formatting of the help message. This class could be inherited and you could override its virtual member functions that handle the printing of the message. A default implementation is provided.

Definition at line 37 of file formatter.hpp.

Member Function Documentation

virtual std::string gears::optparse::formatter::description ( const std::string &  str)
inlinevirtual

Handles the description message. The description is the short brief paragraph that describes the program in the beginning of the help message. By default a newline is appended if the message is non-empty and the wrapped around string is returned.

Parameters
strThe description message.
Returns
The wrapped around description message.

Definition at line 128 of file formatter.hpp.

virtual std::string gears::optparse::formatter::epilogue ( const std::string &  str)
inlinevirtual

Handles the epilogue message. The epilogue is the short brief paragraph at the end of the help message. By default, this string is just wrapped around and nothing else is done to it.

Parameters
strThe epilogue message.
Returns
The wrapped around epilogue message.

Definition at line 146 of file formatter.hpp.

virtual std::string gears::optparse::formatter::options ( const option_set opts)
inlinevirtual

Handles the list of options. This is typically printed after the list of subcommands, if applicable, or the description. This is also typically printed before the epilogue message. By default this returns a string of indented name-help indented pairs. Indentation defaults to 4 spaces.

For options, the default printing is as follows:

Long Form Short Form Metavar Result
"test" 't' "" "-t, &ndash;test "
"test" '\0' "" " &ndash;test "
"" 't' "" "-t "
"test" 't' "to" "-t, &ndash;test[=<to>]"
"" 't' "to" "-t <to> "
Parameters
optsThe current list of active options.
Returns
The resultant string.

Definition at line 214 of file formatter.hpp.

virtual std::string gears::optparse::formatter::subcommands ( const std::vector< subcommand > &  subs)
inlinevirtual

Handles the list of subcommands. This is typically printed after the description in the help message but before the list of options. By default this returns the list of subcommands in name-description indented pairs. Indentation is 4 spaces.

Parameters
subsA vector of optparse::subcommand objects.
Returns
The resultant string.

Definition at line 160 of file formatter.hpp.

virtual std::string gears::optparse::formatter::usage ( const std::string &  name,
const std::string &  command,
const std::string &  str 
)
inlinevirtual

Handles the usage message. The default behaviour wraps around based on usage: {prog} {command} {str}.

Parameters
nameThe program name.
commandThe subcommand name. Empty is not valid.
strThe usage string provided by the user or automatically.
Returns
The resulting usage string.

Definition at line 106 of file formatter.hpp.

virtual std::string gears::optparse::formatter::wrap ( const std::string &  str,
size_t  indent = 0 
)
inlinevirtual

Wraps a string at the column point. It also handles initial indentation size if needed. The implementation by default wraps based on characters determined to be spaces by the std::stringstream object. Indentation is done through spaces.

Parameters
strThe string to wrap around.
indentThe indentation to have.
Returns
The string wrapped around based on column - 2.

Definition at line 61 of file formatter.hpp.