Ookii.CommandLine for C++  2.0.0
localized_string_provider.h
Go to the documentation of this file.
1 #ifndef OOKII_LOCALIZED_STRING_PROVIDER_H_
4 #define OOKII_LOCALIZED_STRING_PROVIDER_H_
5 
6 #pragma once
7 
8 #include "format_helper.h"
9 
10 namespace ookii
11 {
28  template<typename CharType, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
30  {
31  public:
33  using string_type = std::basic_string<CharType, Traits, Alloc>;
35  using string_view_type = std::basic_string_view<CharType, Traits>;
36 
39  {
40  static basic_localized_string_provider default_string_provider;
41  return default_string_provider;
42  }
43 
46  virtual string_type invalid_value(string_view_type argument_name) const
47  {
48  return OOKII_FMT_NS format(defaults::invalid_value_format.data(), argument_name);
49  }
50 
53  virtual string_type unknown_argument(string_view_type argument_name) const
54  {
55  return OOKII_FMT_NS format(defaults::unknown_argument_format.data(), argument_name);
56  }
57 
60  virtual string_type missing_value(string_view_type argument_name) const
61  {
62  return OOKII_FMT_NS format(defaults::missing_value_format.data(), argument_name);
63  }
64 
67  virtual string_type duplicate_argument(string_view_type argument_name) const
68  {
69  return OOKII_FMT_NS format(defaults::duplicate_argument_format.data(), argument_name);
70  }
71 
74  {
75  return defaults::too_many_arguments.data();
76  }
77 
81  {
82  return OOKII_FMT_NS format(defaults::missing_required_argument_format.data(), argument_name);
83  }
84 
88  {
89  return OOKII_FMT_NS format(defaults::combined_short_name_non_switch.data(), argument_name);
90  }
91 
93  virtual string_type unknown_error() const
94  {
95  return defaults::unknown.data();
96  }
97 
101  {
102  return defaults::automatic_help_name.data();
103  }
104 
114  virtual CharType automatic_help_short_name() const
115  {
116  return defaults::automatic_help_short_name;
117  }
118 
122  {
123  return defaults::automatic_help_description.data();
124  }
125 
129  {
130  return defaults::automatic_version_name.data();
131  }
132 
136  {
137  return defaults::automatic_version_command_name.data();
138  }
139 
143  {
144  return defaults::automatic_version_description.data();
145  }
146 
147  private:
148  struct defaults
149  {
150  static constexpr auto invalid_value_format = literal_cast<CharType>("The value provided for the argument '{}' was invalid.");
151  static constexpr auto unknown_argument_format = literal_cast<CharType>("Unknown argument name '{}'.");
152  static constexpr auto missing_value_format = literal_cast<CharType>("No value was supplied for the argument '{}'.");
153  static constexpr auto duplicate_argument_format = literal_cast<CharType>("The argument '{}' was supplied more than once.");
154  static constexpr auto too_many_arguments = literal_cast<CharType>("Too many arguments were supplied.");
155  static constexpr auto missing_required_argument_format = literal_cast<CharType>("The required argument '{}' was not supplied.");
156  static constexpr auto combined_short_name_non_switch = literal_cast<CharType>("The combined short argument '{}' contains an argument that is not a switch.");
157  static constexpr auto unknown = literal_cast<CharType>("An unknown error has occurred.");
158  static constexpr auto automatic_help_name = literal_cast<CharType>("Help");
159  static constexpr CharType automatic_help_short_name = '?';
160  static constexpr auto automatic_help_description = literal_cast<CharType>("Displays this help message.");
161  static constexpr auto automatic_version_name = literal_cast<CharType>("Version");
162  static constexpr auto automatic_version_command_name = literal_cast<CharType>("version");
163  static constexpr auto automatic_version_description = literal_cast<CharType>("Displays version information.");
164  };
165  };
166 
171 
172 }
173 
174 #endif
Provides custom localized strings.
Definition: localized_string_provider.h:30
virtual string_type duplicate_argument(string_view_type argument_name) const
Gets the error message for parse_error::duplicate_argument.
Definition: localized_string_provider.h:67
virtual string_type combined_short_name_non_switch(string_view_type argument_name) const
Gets the error message for parse_error::combined_short_name_non_switch.
Definition: localized_string_provider.h:87
virtual string_type automatic_help_description() const
Gets the description of the help argument created if basic_parser_builder::automatic_help_argument() ...
Definition: localized_string_provider.h:121
virtual string_type too_many_arguments() const
Gets the error message for parse_error::too_many_arguments.
Definition: localized_string_provider.h:73
virtual string_type unknown_error() const
Gets the error message for parse_error::unknown.
Definition: localized_string_provider.h:93
virtual string_type automatic_version_name() const
Gets the name of the version argument created by basic_parser_builder::add_version_argument().
Definition: localized_string_provider.h:128
std::basic_string< CharType, Traits, Alloc > string_type
The concrete string type used.
Definition: localized_string_provider.h:33
static basic_localized_string_provider & get_default() noexcept
Gets a default instance of the basic_localized_string_provider.
Definition: localized_string_provider.h:38
virtual CharType automatic_help_short_name() const
Gets the short name of the help argument created if basic_parser_builder::automatic_help_argument() w...
Definition: localized_string_provider.h:114
virtual string_type automatic_help_name() const
Gets the name of the help argument created if basic_parser_builder::automatic_help_argument() was not...
Definition: localized_string_provider.h:100
virtual string_type automatic_version_command_name() const
Gets the name of the version command created by basic_command_manager::add_version_command().
Definition: localized_string_provider.h:135
virtual string_type invalid_value(string_view_type argument_name) const
Gets the error message for parse_error::invalid_value.
Definition: localized_string_provider.h:46
virtual string_type unknown_argument(string_view_type argument_name) const
Gets the error message for parse_error::unknown_argument.
Definition: localized_string_provider.h:53
std::basic_string_view< CharType, Traits > string_view_type
The concrete string_view type used.
Definition: localized_string_provider.h:35
virtual string_type missing_value(string_view_type argument_name) const
Gets the error message for parse_error::missing_value.
Definition: localized_string_provider.h:60
virtual string_type automatic_version_description() const
Gets the description of the version argument created by basic_parser_builder::add_version_argument().
Definition: localized_string_provider.h:142
virtual string_type missing_required_argument(string_view_type argument_name) const
Gets the error message for parse_error::missing_required_argument.
Definition: localized_string_provider.h:80
Allows selection between the C++20 <format> library and libfmt.
#define OOKII_FMT_NS
The namespace which contains the formatting library.
Definition: format_helper.h:34
Namespace containing the core Ookii.CommandLine.Cpp types.
Definition: command_line_argument.h:16