Ookii.CommandLine for C++  1.0.0
usage_options.h
1 #ifndef OOKII_basic_usage_options_H_
4 #define OOKII_basic_usage_options_H_
5 
6 #pragma once
7 
8 #include "string_helper.h"
9 #include "line_wrapping_stream.h"
10 
11 namespace ookii
12 {
27  template<typename CharType, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
29  {
30  private:
32 
33  std::optional<line_wrapping_stream_type> _owned_output;
34  std::optional<line_wrapping_stream_type> _owned_error;
35 
36  public:
38  struct defaults
39  {
41  static constexpr auto usage_prefix_format = literal_cast<CharType>("Usage: {}");
43  static constexpr auto value_description_format = literal_cast<CharType>("<{}>");
45  static constexpr auto optional_argument_format = literal_cast<CharType>("[{}]");
47  static constexpr auto multi_value_suffix = literal_cast<CharType>("...");
49  static constexpr auto argument_description_format = literal_cast<CharType>(" {}{} {}{}\n{}{}\n");
51  static constexpr auto default_value_format = literal_cast<CharType>(" Default value: {}.");
53  static constexpr auto alias_format = literal_cast<CharType>(" ({})");
55  static constexpr auto alias_separator = literal_cast<CharType>(", ");
56 
58  static constexpr size_t syntax_indent = 3;
60  static constexpr size_t argument_description_indent = 8;
61  };
62 
64  using string_type = std::basic_string<CharType, Traits, Alloc>;
66  using stream_type = std::basic_ostream<CharType, Traits>;
67 
73  : _owned_output{line_wrapping_stream_type::for_cout()},
74  _owned_error{line_wrapping_stream_type::for_cerr()},
75  output{*_owned_output},
76  error{*_owned_error}
77  {
78 
79  }
80 
87  : output{output},
88  error{output}
89  {
90  }
91 
98  : output{output},
99  error{error}
100  {
101  }
102 
105 
108 
113 
118 
123 
126 
139 
144 
149 
152 
159 
166 
176 
181 
186  };
187 
192 }
193 
194 #endif
Output stream that wraps lines on white-space characters at the specified line length,...
Definition: line_wrapping_stream.h:550
Provides options for how to format usage help.
Definition: usage_options.h:29
std::basic_ostream< CharType, Traits > stream_type
The concrete stream type used.
Definition: usage_options.h:66
string_type alias_format
The format to use for the aliases of an argument.
Definition: usage_options.h:148
string_type multi_value_suffix
Suffix to add to the syntax of multi-value arguments.
Definition: usage_options.h:125
bool use_white_space_value_separator
Indicates whether to use white space as the argument name separator in the usage syntax.
Definition: usage_options.h:175
stream_type & error
The stream used to write errors to.
Definition: usage_options.h:107
string_type value_description_format
The format to use for the value description of an argument.
Definition: usage_options.h:117
string_type usage_prefix_format
The format to use for the prefix to the usage syntax.
Definition: usage_options.h:112
string_type alias_separator
The separator to use if the argument has more than one alias.
Definition: usage_options.h:151
size_t argument_description_indent
The level of indentation to use when writing argument descriptions.
Definition: usage_options.h:165
basic_usage_options(stream_type &output)
Initializes a new instance of the basic_usage_options class with the specified stream.
Definition: usage_options.h:86
basic_usage_options()
Initializes a new instance of the basic_usage_options class.
Definition: usage_options.h:72
size_t syntax_indent
The level of indentation to use when writing the usage syntax.
Definition: usage_options.h:158
string_type default_value_format
The format to use for the default value of an argument.
Definition: usage_options.h:143
string_type argument_description_format
The format to use for the description of an argument.
Definition: usage_options.h:138
basic_usage_options(stream_type &output, stream_type &error)
Initializes a new instance of the basic_usage_options class with the specified output and error strea...
Definition: usage_options.h:97
bool include_aliases_in_description
Indicates whether to include the aliases of arguments in the description.
Definition: usage_options.h:185
std::basic_string< CharType, Traits, Alloc > string_type
The concrete string type used.
Definition: usage_options.h:64
bool include_default_value_in_description
Indicates whether to include the default value of arguments in the description.
Definition: usage_options.h:180
stream_type & output
The stream used to write usage help to.
Definition: usage_options.h:104
string_type optional_argument_format
The format to use for the syntax of an optional argument.
Definition: usage_options.h:122
Provides an output stream buffer, and associated stream, that allow for white-space wrapping text at ...
Namespace containing the core Ookii.CommandLine.Cpp types.
Definition: command_line_argument.h:16
Provides helper types and functions for working with strings.
Provides default values for the fields of basic_usage_options.
Definition: usage_options.h:39
static constexpr auto usage_prefix_format
Default value for basic_usage_options::usage_prefix_format.
Definition: usage_options.h:41
static constexpr auto alias_separator
Default value for basic_usage_options::alias_separator.
Definition: usage_options.h:55
static constexpr auto value_description_format
Default value for basic_usage_options::value_description_format.
Definition: usage_options.h:43
static constexpr auto multi_value_suffix
Default value for basic_usage_options::multi_value_suffix.
Definition: usage_options.h:47
static constexpr auto default_value_format
Default value for basic_usage_options::default_value_format.
Definition: usage_options.h:51
static constexpr auto optional_argument_format
Default value for basic_usage_options::optional_argument_format.
Definition: usage_options.h:45
static constexpr auto argument_description_format
Default value for basic_usage_options::argument_description_format.
Definition: usage_options.h:49
static constexpr size_t argument_description_indent
Default value for basic_usage_options::argument_description_indent.
Definition: usage_options.h:60
static constexpr size_t syntax_indent
Default value for basic_usage_options::syntax_indent.
Definition: usage_options.h:58
static constexpr auto alias_format
Default value for basic_usage_options::alias_format.
Definition: usage_options.h:53