Skip to content

Commit

Permalink
Renaming option functions on formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Apr 30, 2018
1 parent 00be549 commit c8bfb5c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
### Version 1.6: Formatters
### Version 1.6: Formatting

Added a new formatting system. You can now set the formatter on Apps and Options.
Added a new formatting system. You can now set the formatter on Apps.

* Added `CLI::Formatter` and `formatter` slot for apps
* Added `CLI::Formatter` and `formatter` slot for apps, inherited.
* Added `help_all` support (not added by default)
* Added filter argument to `get_subcommands`, `get_options`; use empty filter `{}` to avoid filtering
* Added `get_groups()` to get groups
Expand Down
2 changes: 1 addition & 1 deletion examples/formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class MyFormatter : public CLI::Formatter {
public:
std::string make_opts(const CLI::Option *) const override { return " OPTION"; }
std::string make_option_opts(const CLI::Option *) const override { return " OPTION"; }
};

int main(int argc, char **argv) {
Expand Down
12 changes: 6 additions & 6 deletions include/CLI/Formatter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ inline std::string Formatter::make_usage(const App *app, std::string name) const
// Convert to help names
std::vector<std::string> positional_names(positionals.size());
std::transform(positionals.begin(), positionals.end(), positional_names.begin(), [this](const Option *opt) {
return make_usage(opt);
return make_option_usage(opt);
});

out << " " << detail::join(positional_names, " ");
Expand Down Expand Up @@ -182,14 +182,14 @@ inline std::string Formatter::make_expanded(const App *sub) const {
return out.str();
}

inline std::string Formatter::make_name(const Option *opt, bool is_positional) const {
inline std::string Formatter::make_option_name(const Option *opt, bool is_positional) const {
if(is_positional)
return opt->get_name(true, false);
else
return opt->get_name(false, true);
}

inline std::string Formatter::make_opts(const Option *opt) const {
inline std::string Formatter::make_option_opts(const Option *opt) const {
std::stringstream out;

if(opt->get_type_size() != 0) {
Expand Down Expand Up @@ -219,12 +219,12 @@ inline std::string Formatter::make_opts(const Option *opt) const {
return out.str();
}

inline std::string Formatter::make_desc(const Option *opt) const { return opt->get_description(); }
inline std::string Formatter::make_option_desc(const Option *opt) const { return opt->get_description(); }

inline std::string Formatter::make_usage(const Option *opt) const {
inline std::string Formatter::make_option_usage(const Option *opt) const {
// Note that these are positionals usages
std::stringstream out;
out << make_name(opt, true);
out << make_option_name(opt, true);

if(opt->get_expected() > 1)
out << "(" << std::to_string(opt->get_expected()) << "x)";
Expand Down
11 changes: 6 additions & 5 deletions include/CLI/FormatterFwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,22 @@ class Formatter {

virtual std::string make_option(const Option *opt, bool is_positional) const {
std::stringstream out;
detail::format_help(out, make_name(opt, is_positional) + make_opts(opt), make_desc(opt), column_width_);
detail::format_help(
out, make_option_name(opt, is_positional) + make_option_opts(opt), make_option_desc(opt), column_width_);
return out.str();
}

/// @brief This is the name part of an option, Default: left column
virtual std::string make_name(const Option *, bool) const;
virtual std::string make_option_name(const Option *, bool) const;

/// @brief This is the options part of the name, Default: combined into left column
virtual std::string make_opts(const Option *) const;
virtual std::string make_option_opts(const Option *) const;

/// @brief This is the description. Default: Right column, on new line if left column too large
virtual std::string make_desc(const Option *) const;
virtual std::string make_option_desc(const Option *) const;

/// @brief This is used to print the name on the USAGE line
virtual std::string make_usage(const Option *opt) const;
virtual std::string make_option_usage(const Option *opt) const;

///@}
};
Expand Down

0 comments on commit c8bfb5c

Please sign in to comment.