21#ifndef G_OPTIONS_USAGE_H
22#define G_OPTIONS_USAGE_H
69 static constexpr std::size_t default_ =
static_cast<std::size_t
>(-1) ;
88 Config & set_separator(
const std::string & ) ;
89 Config & set_column( std::size_t ) noexcept ;
90 Config & set_width( std::size_t ) noexcept ;
91 Config & set_width2( std::size_t ) noexcept ;
92 Config & set_margin( std::size_t ) noexcept ;
93 Config & set_extra(
bool =
true ) noexcept ;
94 Config & set_alt_usage(
bool = true ) noexcept ;
96 Config & set_level_max(
unsigned int ) noexcept ;
97 Config & set_level_min(
unsigned int ) noexcept ;
98 Config & set_main_tag(
unsigned int ) noexcept ;
99 Config & set_tag_bits(
unsigned int ) noexcept ;
101 Config & setWidthsWrtMargin() ;
102 Config & setOverflowFormat(
char = ' ' ) ;
111 const
std::
string & args = {} )
const ;
124 std::string
help(
const Config & ,
bool * overflow_p =
nullptr )
const ;
131 void output(
const Config & , std::ostream & stream ,
132 const std::string & exe ,
const std::string & args = {} )
const ;
136 static SortFn
sort() ;
141 std::string summaryPartOne(
const Config & )
const ;
142 std::string summaryPartTwo(
const Config & )
const ;
143 std::string helpSyntax(
const Option & ,
bool =
false ,
char =
'\0' )
const ;
144 std::string helpDescription(
const Option & ,
bool )
const ;
145 std::string helpSeparator(
const Config & , std::size_t syntax_length )
const ;
146 std::string helpPadding(
const Config & )
const ;
147 std::string helpImp(
const Config & ,
bool ,
bool & )
const ;
148 std::string optionHelp(
const Config & ,
const Option & option ,
bool ,
bool & )
const ;
149 std::string helpWrap(
const Config & ,
const std::string & syntax_simple ,
150 const std::string & syntax_aligned ,
const std::string &
separator ,
151 const std::string & description ,
bool ,
bool & )
const ;
152 static Config setDefaults(
const Config & ) ;
153 static Config setWidthsWrtMargin(
const Config & ) ;
156 std::vector<Option> m_options ;
157 char m_space_margin {
' '} ;
158 char m_space_separator {
' '} ;
159 char m_space_indent {
' '} ;
160 char m_space_padding {
' '} ;
161 char m_space_overflow {
' '} ;
162 char m_space_syntax {
' '} ;
165inline G::OptionsUsage::Config & G::OptionsUsage::Config::set_separator(
const std::string & s ) { separator = s ;
return *this ; }
166inline G::OptionsUsage::Config & G::OptionsUsage::Config::set_column( std::size_t n )
noexcept { column = n ;
return *this ; }
167inline G::OptionsUsage::Config & G::OptionsUsage::Config::set_width( std::size_t n )
noexcept { width = n ;
return *this ; }
168inline G::OptionsUsage::Config & G::OptionsUsage::Config::set_width2( std::size_t n )
noexcept { width2 = n ;
return *this ; }
169inline G::OptionsUsage::Config & G::OptionsUsage::Config::set_margin( std::size_t n )
noexcept { margin = n ;
return *this ; }
170inline G::OptionsUsage::Config & G::OptionsUsage::Config::set_extra(
bool b )
noexcept { extra = b ;
return *this ; }
171inline G::OptionsUsage::Config & G::OptionsUsage::Config::set_alt_usage(
bool b )
noexcept { alt_usage = b ;
return *this ; }
172inline G::OptionsUsage::Config & G::OptionsUsage::Config::set_level_max(
unsigned int n )
noexcept { level_max = n ;
return *this ; }
173inline G::OptionsUsage::Config & G::OptionsUsage::Config::set_level_min(
unsigned int n )
noexcept { level_min = n ;
return *this ; }
174inline G::OptionsUsage::Config & G::OptionsUsage::Config::set_main_tag(
unsigned int n )
noexcept { main_tag = n ;
return *this ; }
175inline G::OptionsUsage::Config & G::OptionsUsage::Config::set_tag_bits(
unsigned int n )
noexcept { tag_bits = n ;
return *this ; }
Provides help text for a set of options.
static SortFn sort()
Returns the default sort function that sorts by level first and then by name.
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>".
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().
std::string help(const Config &, bool *overflow_p=nullptr) const
Returns a multi-line string giving help on each option.
A structure representing a G::Options command-line option.
A configuration structure for G::OptionsUsage.
bool alt_usage
use alternate "usage:" string
std::size_t overflow_spaces
'overflow' format extra spaces on wrapped lines
std::size_t width
overall width for wrapping, or zero for none, defaults to $COLUMNS
unsigned int level_max
show options at-or-below this level
unsigned int level_min
.. and at-or-above this level
std::size_t separator_spaces
extra spaces on wrapped lines if using a separator
std::size_t overflow
use 'overflow' format if rhs is squashed down to this
std::string separator
separator between syntax and description
unsigned int tag_bits
show options with matching tag bits, or zero for all
std::size_t margin
spaces added to the left
unsigned int main_tag
show options with this main tag, or zero for all
bool extra
include descriptions' extra text
std::size_t column
left hand column width if no separator (includes margin)
std::size_t width2
width after the first line, or zero for 'width'