Warning, file /afterburner/cpp/external/CLI/FormatterFwd.hpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009
0010 #include <map>
0011 #include <string>
0012 #include <utility>
0013 #include <vector>
0014
0015
0016 #include "StringTools.hpp"
0017
0018 namespace CLI {
0019
0020
0021 class Option;
0022 class App;
0023
0024
0025
0026
0027
0028
0029 enum class AppFormatMode {
0030 Normal,
0031 All,
0032 Sub,
0033 };
0034
0035
0036
0037
0038
0039 class FormatterBase {
0040 protected:
0041
0042
0043
0044
0045 std::size_t column_width_{30};
0046
0047
0048
0049 std::map<std::string, std::string> labels_{};
0050
0051
0052
0053
0054
0055 public:
0056 FormatterBase() = default;
0057 FormatterBase(const FormatterBase &) = default;
0058 FormatterBase(FormatterBase &&) = default;
0059
0060
0061 virtual ~FormatterBase() noexcept {}
0062
0063
0064 virtual std::string make_help(const App *, std::string, AppFormatMode) const = 0;
0065
0066
0067
0068
0069
0070
0071 void label(std::string key, std::string val) { labels_[key] = val; }
0072
0073
0074 void column_width(std::size_t val) { column_width_ = val; }
0075
0076
0077
0078
0079
0080
0081 std::string get_label(std::string key) const {
0082 if(labels_.find(key) == labels_.end())
0083 return key;
0084 else
0085 return labels_.at(key);
0086 }
0087
0088
0089 std::size_t get_column_width() const { return column_width_; }
0090
0091
0092 };
0093
0094
0095 class FormatterLambda final : public FormatterBase {
0096 using funct_t = std::function<std::string(const App *, std::string, AppFormatMode)>;
0097
0098
0099 funct_t lambda_;
0100
0101 public:
0102
0103 explicit FormatterLambda(funct_t funct) : lambda_(std::move(funct)) {}
0104
0105
0106 ~FormatterLambda() noexcept override {}
0107
0108
0109 std::string make_help(const App *app, std::string name, AppFormatMode mode) const override {
0110 return lambda_(app, name, mode);
0111 }
0112 };
0113
0114
0115
0116 class Formatter : public FormatterBase {
0117 public:
0118 Formatter() = default;
0119 Formatter(const Formatter &) = default;
0120 Formatter(Formatter &&) = default;
0121
0122
0123
0124
0125
0126
0127 virtual std::string make_group(std::string group, bool is_positional, std::vector<const Option *> opts) const;
0128
0129
0130 virtual std::string make_positionals(const App *app) const;
0131
0132
0133 std::string make_groups(const App *app, AppFormatMode mode) const;
0134
0135
0136 virtual std::string make_subcommands(const App *app, AppFormatMode mode) const;
0137
0138
0139 virtual std::string make_subcommand(const App *sub) const;
0140
0141
0142 virtual std::string make_expanded(const App *sub) const;
0143
0144
0145 virtual std::string make_footer(const App *app) const;
0146
0147
0148 virtual std::string make_description(const App *app) const;
0149
0150
0151 virtual std::string make_usage(const App *app, std::string name) const;
0152
0153
0154 std::string make_help(const App * , std::string, AppFormatMode) const override;
0155
0156
0157
0158
0159
0160
0161 virtual std::string make_option(const Option *opt, bool is_positional) const {
0162 std::stringstream out;
0163 detail::format_help(
0164 out, make_option_name(opt, is_positional) + make_option_opts(opt), make_option_desc(opt), column_width_);
0165 return out.str();
0166 }
0167
0168
0169 virtual std::string make_option_name(const Option *, bool) const;
0170
0171
0172 virtual std::string make_option_opts(const Option *) const;
0173
0174
0175 virtual std::string make_option_desc(const Option *) const;
0176
0177
0178 virtual std::string make_option_usage(const Option *opt) const;
0179
0180
0181 };
0182
0183
0184 }