cli11
Loading...
Searching...
No Matches
cli::formatter_t Class Referenceexport
module cli11

The default help formatter. More...

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

Public Member Functions

 formatter_t (const formatter_t &)=default
 formatter_t (formatter_t &&)=default
auto operator= (const formatter_t &) -> formatter_t &=default
auto operator= (formatter_t &&) -> formatter_t &=default
Overridables
virtual auto make_group (std::string group, bool is_positional, std::vector< const option_t * > opts) const -> std::string
 Renders one named group of options.
virtual auto make_positionals (const app_t *app) const -> std::string
 Renders the positional arguments section.
auto make_groups (const app_t *app, app_format_mode_t mode) const -> std::string
 Renders every option group.
virtual auto make_subcommands (const app_t *app, app_format_mode_t mode) const -> std::string
 Renders the subcommand list.
virtual auto make_subcommand (const app_t *sub) const -> std::string
 Renders a single subcommand entry.
virtual auto make_expanded (const app_t *sub, app_format_mode_t mode) const -> std::string
 Renders a subcommand expanded in full.
virtual auto make_footer (const app_t *app) const -> std::string
 Renders the footer.
virtual auto make_description (const app_t *app) const -> std::string
 Renders the description paragraph.
virtual auto make_usage (const app_t *app, std::string name) const -> std::string
 Renders the usage line.
auto make_help (const app_t *app, std::string name, app_format_mode_t mode) const -> std::string override
 Assembles the complete help page.
Options
virtual auto make_option (const option_t *opt, bool is_positional) const -> std::string
 Renders a single option entry.
virtual auto make_option_name (const option_t *opt, bool is_positional) const -> std::string
 Renders the name column of an option entry.
virtual auto make_option_opts (const option_t *opt) const -> std::string
 Renders the qualifiers that follow an option's name.
virtual auto make_option_desc (const option_t *opt) const -> std::string
 Renders an option's description column.
virtual auto make_option_usage (const option_t *opt) const -> std::string
 Renders how an option appears in the usage line.
Public Member Functions inherited from cli::formatter_base_t
 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
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.
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.

Additional Inherited Members

static auto default_label (std::string_view key) -> std::string
 The label used when no override is set.
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.

Detailed Description

The default help formatter.

Each piece of the help page is a separate virtual, so a derived formatter can replace one section without reimplementing the rest.

Member Function Documentation

◆ make_description()

auto cli::formatter_t::make_description ( const app_t * app) const -> std::string
nodiscardvirtual

Renders the description paragraph.

Parameters
appThe application to describe.
Returns
The rendered description.

◆ make_expanded()

auto cli::formatter_t::make_expanded ( const app_t * sub,
app_format_mode_t mode ) const -> std::string
nodiscardvirtual

Renders a subcommand expanded in full.

Parameters
subThe subcommand to describe.
modeHow much detail to include.
Returns
The rendered entry.

◆ make_footer()

auto cli::formatter_t::make_footer ( const app_t * app) const -> std::string
nodiscardvirtual

Renders the footer.

Parameters
appThe application to describe.
Returns
The rendered footer.

◆ make_group()

auto cli::formatter_t::make_group ( std::string group,
bool is_positional,
std::vector< const option_t * > opts ) const -> std::string
nodiscardvirtual

Renders one named group of options.

Parameters
groupThe group name.
is_positionalWhether the group holds positionals.
optsThe options in the group.
Returns
The rendered group.

◆ make_groups()

auto cli::formatter_t::make_groups ( const app_t * app,
app_format_mode_t mode ) const -> std::string
nodiscard

Renders every option group.

Parameters
appThe application to describe.
modeHow much detail to include.
Returns
The rendered sections.

◆ make_help()

auto cli::formatter_t::make_help ( const app_t * app,
std::string name,
app_format_mode_t mode ) const -> std::string
nodiscardoverridevirtual

Assembles the 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.

Implements cli::formatter_base_t.

◆ make_option()

auto cli::formatter_t::make_option ( const option_t * opt,
bool is_positional ) const -> std::string
nodiscardvirtual

Renders a single option entry.

Parameters
optThe option to describe.
is_positionalWhether the option is a positional.
Returns
The rendered entry.

◆ make_option_desc()

auto cli::formatter_t::make_option_desc ( const option_t * opt) const -> std::string
nodiscardvirtual

Renders an option's description column.

Parameters
optThe option to describe.
Returns
The rendered description.

◆ make_option_name()

auto cli::formatter_t::make_option_name ( const option_t * opt,
bool is_positional ) const -> std::string
nodiscardvirtual

Renders the name column of an option entry.

Parameters
optThe option to describe.
is_positionalWhether the option is a positional.
Returns
The rendered name column.

◆ make_option_opts()

auto cli::formatter_t::make_option_opts ( const option_t * opt) const -> std::string
nodiscardvirtual

Renders the qualifiers that follow an option's name.

Parameters
optThe option to describe.
Returns
The rendered qualifiers.

◆ make_option_usage()

auto cli::formatter_t::make_option_usage ( const option_t * opt) const -> std::string
nodiscardvirtual

Renders how an option appears in the usage line.

Parameters
optThe option to describe.
Returns
The rendered usage fragment.

◆ make_positionals()

auto cli::formatter_t::make_positionals ( const app_t * app) const -> std::string
nodiscardvirtual

Renders the positional arguments section.

Parameters
appThe application to describe.
Returns
The rendered section.

◆ make_subcommand()

auto cli::formatter_t::make_subcommand ( const app_t * sub) const -> std::string
nodiscardvirtual

Renders a single subcommand entry.

Parameters
subThe subcommand to describe.
Returns
The rendered entry.

◆ make_subcommands()

auto cli::formatter_t::make_subcommands ( const app_t * app,
app_format_mode_t mode ) const -> std::string
nodiscardvirtual

Renders the subcommand list.

Parameters
appThe application to describe.
modeHow much detail to include.
Returns
The rendered section.

◆ make_usage()

auto cli::formatter_t::make_usage ( const app_t * app,
std::string name ) const -> std::string
nodiscardvirtual

Renders the usage line.

Parameters
appThe application to describe.
nameThe name to present the application under.
Returns
The rendered usage line.

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