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

Interface for converting between an application and a configuration file. More...

Inheritance diagram for cli::config_t:
cli::config_base_t cli::config_ini_t

Public Member Functions

 config_t (const config_t &)=default
 config_t (config_t &&)=default
auto operator= (const config_t &) -> config_t &=default
auto operator= (config_t &&) -> config_t &=default
virtual auto to_config (const app_t *app, bool default_also, bool write_description, std::string prefix) const -> std::string=0
 Writes an application out as configuration text.
virtual auto to_config (const app_t *app, config_output_mode_t mode, bool write_description, std::string prefix) const -> std::string
 Writes an application out as configuration text.
virtual auto from_config (std::istream &input) const -> std::vector< config_item_t >=0
 Reads configuration text into a list of entries.
virtual auto to_flag (const config_item_t &item) const -> std::string
 Reduces an entry to a single flag value.
auto from_file (const std::string &name) const -> std::vector< config_item_t >
 Reads a configuration file into a list of entries.

Protected Attributes

std::vector< config_item_titems {}
 Entries accumulated while reading.

Detailed Description

Interface for converting between an application and a configuration file.

Member Function Documentation

◆ from_config()

virtual auto cli::config_t::from_config ( std::istream & input) const -> std::vector< config_item_t >
nodiscardpure virtual

Reads configuration text into a list of entries.

Parameters
inputThe stream to read from.
Returns
The entries that were read.

Implemented in cli::config_base_t.

◆ from_file()

auto cli::config_t::from_file ( const std::string & name) const -> std::vector< config_item_t >
inlinenodiscard

Reads a configuration file into a list of entries.

Parameters
namePath to the file.
Returns
The entries that were read.
Exceptions
cli::file_error_tIf the file cannot be opened.
cli::config_error_tIf the contents cannot be parsed.

◆ to_config() [1/2]

virtual auto cli::config_t::to_config ( const app_t * app,
bool default_also,
bool write_description,
std::string prefix ) const -> std::string
nodiscardpure virtual

Writes an application out as configuration text.

Parameters
appThe application to describe.
default_alsoInclude options left at their defaults.
write_descriptionInclude descriptions as comments.
prefixSection prefix to write entries under.
Returns
The configuration text.

Implemented in cli::config_base_t.

◆ to_config() [2/2]

virtual auto cli::config_t::to_config ( const app_t * app,
config_output_mode_t mode,
bool write_description,
std::string prefix ) const -> std::string
inlinenodiscardvirtual

Writes an application out as configuration text.

Parameters
appThe application to describe.
modeHow much of the application to write.
write_descriptionInclude descriptions as comments.
prefixSection prefix to write entries under.
Returns
The configuration text.

Reimplemented in cli::config_base_t.

◆ to_flag()

virtual auto cli::config_t::to_flag ( const config_item_t & item) const -> std::string
inlinenodiscardvirtual

Reduces an entry to a single flag value.

Parameters
itemThe entry to reduce.
Returns
The single value, or "{}" if the entry has none.
Exceptions
cli::conversion_error_tIf the entry has more than one value.

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