cli11
Loading...
Searching...
No Matches
cli::formatter_base_t Class Referenceabstractexport
module cli11

Layout settings and labels shared by every formatter. More...

Inheritance diagram for cli::formatter_base_t:
cli::formatter_lambda_t cli::formatter_t

Public Member Functions

Basics
 formatter_base_t (const formatter_base_t &)=default
 formatter_base_t (formatter_base_t &&)=default
auto operator= (const formatter_base_t &) -> formatter_base_t &=default
auto operator= (formatter_base_t &&) -> formatter_base_t &=default
virtual auto make_help (const app_t *app, std::string name, app_format_mode_t mode) const -> std::string=0
 Assembles a complete help page.
Setters
auto label (std::string key, std::string val) -> void
 Overrides a section label.
auto column_width (std::size_t val) -> void
 Sets the width of the left column.
auto long_option_alignment_ratio (float ratio) -> void
 Sets the alignment ratio for long options in the left column.
auto right_column_width (std::size_t val) -> void
 Sets the width of the right column.
auto description_paragraph_width (std::size_t val) -> void
 Sets the width of the description paragraph.
auto footer_paragraph_width (std::size_t val) -> void
 Sets the width of the footer paragraph.
auto enable_description_formatting (bool value=true) -> void
 Enables or disables reflowing of the description paragraph.
auto enable_footer_formatting (bool value=true) -> void
 Enables or disables reflowing of the footer paragraph.
auto enable_option_defaults (bool value=true) -> void
 Enables or disables printing of option default values.
auto enable_option_type_names (bool value=true) -> void
 Enables or disables printing of option type names.
auto enable_default_flag_values (bool value=true) -> void
 Enables or disables printing of default flag values.
Getters
auto get_label (std::string_view key) const -> std::string
 Resolves a section label, applying any override.
auto get_column_width () const -> std::size_t
 Returns the width of the left column.
auto get_right_column_width () const -> std::size_t
 Returns the width of the right column.
auto get_description_paragraph_width () const -> std::size_t
 Returns the width of the description paragraph.
auto get_footer_paragraph_width () const -> std::size_t
 Returns the width of the footer paragraph.
auto get_long_option_alignment_ratio () const -> float
 Returns the alignment ratio for long options.
auto is_description_paragraph_formatting_enabled () const -> bool
 Reports whether the description paragraph is reflowed.
auto is_footer_paragraph_formatting_enabled () const -> bool
 Reports whether the footer paragraph is reflowed.
auto is_option_defaults_enabled () const -> bool
 Reports whether option default values are printed.
auto is_option_type_names_enabled () const -> bool
 Reports whether option type names are printed.
auto is_default_flag_values_enabled () const -> bool
 Reports whether default flag values are printed.

Options

std::size_t column_width_ {30}
 The width of the left column (options, flags, subcommands).
float long_option_alignment_ratio_ {1 / 3.f}
 The alignment ratio for long options within the left column.
std::size_t right_column_width_ {65}
 The width of the right column (descriptions).
std::size_t description_paragraph_width_ {80}
 The width of the description paragraph at the top of the help.
std::size_t footer_paragraph_width_ {80}
 The width of the footer paragraph.
bool enable_description_formatting_ {true}
 Whether the description paragraph is reflowed.
bool enable_footer_formatting_ {true}
 Whether the footer paragraph is reflowed.
bool enable_option_defaults_ {true}
 Whether option default values are printed.
bool enable_option_type_names_ {true}
 Whether option type names are printed.
bool enable_default_flag_values_ {true}
 Whether default flag values are printed.
std::map< std::string, std::string, std::less<> > labels_ {}
 User overrides for the section labels.
static auto default_label (std::string_view key) -> std::string
 The label used when no override is set.

Detailed Description

Layout settings and labels shared by every formatter.

Member Function Documentation

◆ column_width()

auto cli::formatter_base_t::column_width ( std::size_t val) -> void
inline

Sets the width of the left column.

Parameters
valThe new width, in characters.

◆ default_label()

auto cli::formatter_base_t::default_label ( std::string_view key) -> std::string
inlinestaticnodiscardprotected

The label used when no override is set.

Parameters
keyThe label to resolve.
Returns
key unchanged.

◆ description_paragraph_width()

auto cli::formatter_base_t::description_paragraph_width ( std::size_t val) -> void
inline

Sets the width of the description paragraph.

Parameters
valThe new width, in characters.

◆ enable_default_flag_values()

auto cli::formatter_base_t::enable_default_flag_values ( bool value = true) -> void
inline

Enables or disables printing of default flag values.

Parameters
valueWhether to print default flag values.

◆ enable_description_formatting()

auto cli::formatter_base_t::enable_description_formatting ( bool value = true) -> void
inline

Enables or disables reflowing of the description paragraph.

Parameters
valueWhether to reflow.

◆ enable_footer_formatting()

auto cli::formatter_base_t::enable_footer_formatting ( bool value = true) -> void
inline

Enables or disables reflowing of the footer paragraph.

Parameters
valueWhether to reflow.

◆ enable_option_defaults()

auto cli::formatter_base_t::enable_option_defaults ( bool value = true) -> void
inline

Enables or disables printing of option default values.

Parameters
valueWhether to print defaults.

◆ enable_option_type_names()

auto cli::formatter_base_t::enable_option_type_names ( bool value = true) -> void
inline

Enables or disables printing of option type names.

Parameters
valueWhether to print type names.

◆ footer_paragraph_width()

auto cli::formatter_base_t::footer_paragraph_width ( std::size_t val) -> void
inline

Sets the width of the footer paragraph.

Parameters
valThe new width, in characters.

◆ get_column_width()

auto cli::formatter_base_t::get_column_width ( ) const -> std::size_t
inlinenodiscard

Returns the width of the left column.

Returns
The width, in characters.

◆ get_description_paragraph_width()

auto cli::formatter_base_t::get_description_paragraph_width ( ) const -> std::size_t
inlinenodiscard

Returns the width of the description paragraph.

Returns
The width, in characters.

◆ get_footer_paragraph_width()

auto cli::formatter_base_t::get_footer_paragraph_width ( ) const -> std::size_t
inlinenodiscard

Returns the width of the footer paragraph.

Returns
The width, in characters.

◆ get_label()

auto cli::formatter_base_t::get_label ( std::string_view key) const -> std::string
inlinenodiscard

Resolves a section label, applying any override.

Parameters
keyThe label to resolve.
Returns
The override if one is set, otherwise key unchanged.

◆ get_long_option_alignment_ratio()

auto cli::formatter_base_t::get_long_option_alignment_ratio ( ) const -> float
inlinenodiscard

Returns the alignment ratio for long options.

Returns
The ratio.

◆ get_right_column_width()

auto cli::formatter_base_t::get_right_column_width ( ) const -> std::size_t
inlinenodiscard

Returns the width of the right column.

Returns
The width, in characters.

◆ is_default_flag_values_enabled()

auto cli::formatter_base_t::is_default_flag_values_enabled ( ) const -> bool
inlinenodiscard

Reports whether default flag values are printed.

Returns
true if default flag values are printed.

◆ is_description_paragraph_formatting_enabled()

auto cli::formatter_base_t::is_description_paragraph_formatting_enabled ( ) const -> bool
inlinenodiscard

Reports whether the description paragraph is reflowed.

Returns
true if reflowing is enabled.

◆ is_footer_paragraph_formatting_enabled()

auto cli::formatter_base_t::is_footer_paragraph_formatting_enabled ( ) const -> bool
inlinenodiscard

Reports whether the footer paragraph is reflowed.

Returns
true if reflowing is enabled.

◆ is_option_defaults_enabled()

auto cli::formatter_base_t::is_option_defaults_enabled ( ) const -> bool
inlinenodiscard

Reports whether option default values are printed.

Returns
true if defaults are printed.

◆ is_option_type_names_enabled()

auto cli::formatter_base_t::is_option_type_names_enabled ( ) const -> bool
inlinenodiscard

Reports whether option type names are printed.

Returns
true if type names are printed.

◆ label()

auto cli::formatter_base_t::label ( std::string key,
std::string val ) -> void
inline

Overrides a section label.

Parameters
keyThe label to override.
valThe replacement text.

◆ long_option_alignment_ratio()

auto cli::formatter_base_t::long_option_alignment_ratio ( float ratio) -> void
inline

Sets the alignment ratio for long options in the left column.

Values outside [0, 1] are folded back into range.

Parameters
ratioThe new ratio.

◆ make_help()

virtual auto cli::formatter_base_t::make_help ( const app_t * app,
std::string name,
app_format_mode_t mode ) const -> std::string
nodiscardpure virtual

Assembles a complete help page.

Parameters
appThe application to describe.
nameThe name to present the application under.
modeHow much detail to include.
Returns
The rendered help page.

Implemented in cli::formatter_lambda_t, and cli::formatter_t.

◆ right_column_width()

auto cli::formatter_base_t::right_column_width ( std::size_t val) -> void
inline

Sets the width of the right column.

Parameters
valThe new width, in characters.

Member Data Documentation

◆ labels_

std::map<std::string, std::string, std::less<> > cli::formatter_base_t::labels_ {}
protected

User overrides for the section labels.

Uses a transparent comparator so lookups accept std::string_view without allocating.


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