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 ) ;
90 Config & set_width( std::size_t ) ;
91 Config & set_width2( std::size_t ) ;
92 Config & set_margin( std::size_t ) ;
93 Config & set_extra(
bool =
true ) ;
94 Config & set_alt_usage(
bool =
true ) ;
96 Config & set_level_max(
unsigned int ) ;
97 Config & set_level_min(
unsigned int ) ;
98 Config & set_main_tag(
unsigned int ) ;
99 Config & set_tag_bits(
unsigned int ) ;
101 Config & setWidthsWrtMargin() ;
102 Config & setOverflowFormat(
char =
' ' ) ;
105 using SortFn = std::function<bool(
const Option&,
const Option&)> ;
110 std::string
summary(
const Config & ,
const std::string & exe ,
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() ;
140 std::string summaryPartOne(
const Config & )
const ;
141 std::string summaryPartTwo(
const Config & )
const ;
142 std::string helpSyntax(
const Option & ,
bool =
false ,
char =
'\0' )
const ;
143 std::string helpDescription(
const Option & ,
bool )
const ;
144 std::string helpSeparator(
const Config & , std::size_t syntax_length )
const ;
145 std::string helpPadding(
const Config & )
const ;
146 std::string helpImp(
const Config & ,
bool ,
bool & )
const ;
147 std::string optionHelp(
const Config & ,
const Option & option ,
bool ,
bool & )
const ;
148 std::string helpWrap(
const Config & ,
const std::string & separator ,
149 const std::string & syntax ,
const std::string & syntax2 ,
150 const std::string & description ,
bool ,
bool & )
const ;
151 static Config setDefaults(
const Config & ) ;
152 static Config setWidthsWrtMargin(
const Config & ) ;
155 std::vector<Option> m_options ;
156 char m_space_margin {
' '} ;
157 char m_space_separator {
' '} ;
158 char m_space_indent {
' '} ;
159 char m_space_padding {
' '} ;
160 char m_space_overflow {
' '} ;
161 char m_space_syntax {
' '} ;
165inline G::OptionsUsage::Config & G::OptionsUsage::Config::set_column( std::size_t n ) { column = n ;
return *this ; }
166inline G::OptionsUsage::Config & G::OptionsUsage::Config::set_width( std::size_t n ) { width = n ;
return *this ; }
167inline G::OptionsUsage::Config & G::OptionsUsage::Config::set_width2( std::size_t n ) { width2 = n ;
return *this ; }
168inline G::OptionsUsage::Config & G::OptionsUsage::Config::set_margin( std::size_t n ) { margin = n ;
return *this ; }
170inline G::OptionsUsage::Config & G::OptionsUsage::Config::set_alt_usage(
bool b ) { alt_usage = b ;
return *this ; }
171inline G::OptionsUsage::Config & G::OptionsUsage::Config::set_level_max(
unsigned int n ) { level_max = n ;
return *this ; }
172inline G::OptionsUsage::Config & G::OptionsUsage::Config::set_level_min(
unsigned int n ) { level_min = n ;
return *this ; }
173inline G::OptionsUsage::Config & G::OptionsUsage::Config::set_main_tag(
unsigned int n ) { main_tag = n ;
return *this ; }
174inline G::OptionsUsage::Config & G::OptionsUsage::Config::set_tag_bits(
unsigned int n ) { tag_bits = n ;
return *this ; }
Provides help text for a set of options.
static SortFn sort()
Returns the default sort function.
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.
OptionsUsage(const std::vector< Option > &, SortFn=sort())
Constructor.
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'