33 struct OptionsLayout ;
69 G_EXCEPTION( InvalidSpecification ,
"invalid options specification string" ) ;
71 explicit Options(
const std::string & spec ,
char sep_major =
'|' ,
char sep_minor =
'!' ,
char escape =
'^' ) ;
98 std::string
lookup(
char c )
const ;
102 bool valid(
const std::string & )
const ;
105 bool visible(
const std::string & name ,
unsigned int level ,
bool level_exact =
false )
const ;
110 bool visible(
const std::string & name )
const ;
114 bool valued(
char )
const ;
120 bool valued(
const std::string & )
const ;
133 bool unvalued(
const std::string & )
const ;
137 bool defaulting(
const std::string & )
const ;
146 const std::string & exe ,
const std::string & args = std::string() )
const ;
163 const std::string & exe ,
const std::string & args = std::string() )
const ;
170 enum class Multiplicity { zero , zero_or_one , one , many } ;
173 std::string description ;
174 std::string description_extra ;
175 Multiplicity value_multiplicity ;
177 std::string value_description ;
180 Option(
char c_ ,
const std::string & name_ ,
const std::string & description_ ,
181 const std::string & description_extra_ ,
const std::string & multiplicity_ ,
182 const std::string & vd_ ,
unsigned int level_ ) ;
183 static Multiplicity decode(
const std::string & ) ;
185 using Map = std::map<std::string,Option> ;
188 void parseSpec(
const std::string & spec ,
char ,
char ,
char ) ;
189 void addImp(
const std::string & ,
char c ,
const std::string & ,
const std::string & ,
190 const std::string & ,
const std::string & ,
unsigned int ) ;
191 std::string usageSummaryPartOne(
const Layout & )
const ;
192 std::string usageSummaryPartTwo(
const Layout & )
const ;
193 std::string usageHelpSyntax( Map::const_iterator )
const ;
194 std::string usageHelpDescription( Map::const_iterator ,
const Layout & )
const ;
195 std::string usageHelpSeparator(
const Layout & , std::size_t syntax_length )
const ;
196 std::string usageHelpWrap(
const Layout & ,
const std::string & line_in ,
197 const std::string & )
const ;
198 std::string usageHelpImp(
const Layout & )
const ;
199 static std::size_t longestSubLine(
const std::string & ) ;
207inline G::OptionsLayout & G::OptionsLayout::set_extra(
bool e ) { extra = e ;
return *this ; }
208inline G::OptionsLayout & G::OptionsLayout::set_level(
unsigned int l ) { level = l ;
return *this ; }
209inline G::OptionsLayout & G::OptionsLayout::set_level_if(
bool b ,
unsigned int l ) {
if(b) level = l ;
return *this ; }
210inline G::OptionsLayout & G::OptionsLayout::set_level_exact(
bool le ) { level_exact = le ;
return *this ; }
211inline G::OptionsLayout & G::OptionsLayout::set_alt_usage(
bool au ) { alt_usage = au ;
return *this ; }
A class to represent allowed command-line options and to provide command-line usage text.
std::string lookup(char c) const
Converts from short-form option character to the corresponding long-form name.
bool unvalued(const std::string &) const
Returns true if the given option name is valid and takes no value.
const StringArray & names() const
Returns the sorted list of long-form option names.
bool visible(const std::string &name, unsigned int level, bool level_exact=false) const
Returns true if the option is visible at the given level.
bool defaulting(const std::string &) const
Returns true if the given long-form single-valued() option can optionally have no explicit value,...
bool valid(const std::string &) const
Returns true if the long-form option name is valid.
void add(StringArray)
Adds one component of the specification, broken down into its seven separate parts.
bool multivalued(char) const
Returns true if the short-form option can have multiple values.
std::string usageSummary(const Layout &, const std::string &exe, const std::string &args=std::string()) const
Returns a one-line (or line-wrapped) usage summary, as "usage: <exe> <options> <args>".
bool valued(char) const
Returns true if the given short-form option takes a value, Returns true if the short-form option char...
void showUsage(const Layout &, std::ostream &stream, const std::string &exe, const std::string &args=std::string()) const
Streams out multi-line usage text using usageSummary() and usageHelp().
Options()
Default constructor for no options.
std::string usageHelp(const Layout &) const
Returns a multi-line string giving help on each option.
std::vector< std::string > StringArray
A std::vector of std::strings.
Describes the layout for G::Options output.
std::size_t column
left hand column width if no separator (includes margin)
std::size_t margin
spaces to the left of the syntax part
std::size_t width
overall width for wrapping, or zero for none
std::string separator
separator between syntax and description
bool extra
include descriptions' extra text
std::size_t width2
width after the first line, or zero for 'width'
unsigned int level
show options at-or-below this level
bool level_exact
.. or exactly at that level
bool alt_usage
use alternate "usage:" string