Commit 27f718125d0e0e2b6c49d5092f82bafcbb8a3ee3

Authored by Henry Fredrick Schreiner
1 parent f24561f4

Reformat with clang-format

.clang-format 0 → 100644
  1 +Language: Cpp
  2 +BasedOnStyle: LLVM
  3 +# AccessModifierOffset: -2
  4 +# AlignAfterOpenBracket: Align
  5 +# AlignConsecutiveAssignments: false
  6 +# AlignConsecutiveDeclarations: false
  7 +# AlignEscapedNewlinesLeft: false
  8 +# AlignOperands: true
  9 +# AlignTrailingComments: true
  10 +# AllowAllParametersOfDeclarationOnNextLine: true
  11 +# AllowShortBlocksOnASingleLine: false
  12 +# AllowShortCaseLabelsOnASingleLine: false
  13 +# AllowShortFunctionsOnASingleLine: All
  14 +# AllowShortIfStatementsOnASingleLine: false
  15 +# AllowShortLoopsOnASingleLine: false
  16 +# AlwaysBreakAfterDefinitionReturnType: None
  17 +# AlwaysBreakAfterReturnType: None
  18 +# AlwaysBreakBeforeMultilineStrings: false
  19 +# AlwaysBreakTemplateDeclarations: false
  20 +BinPackArguments: false
  21 +BinPackParameters: false
  22 +# BraceWrapping:
  23 +# AfterClass: false
  24 +# AfterControlStatement: false
  25 +# AfterEnum: false
  26 +# AfterFunction: false
  27 +# AfterNamespace: false
  28 +# AfterObjCDeclaration: false
  29 +# AfterStruct: false
  30 +# AfterUnion: false
  31 +# BeforeCatch: false
  32 +# BeforeElse: false
  33 +# IndentBraces: false
  34 +# BreakBeforeBinaryOperators: None
  35 +# BreakBeforeBraces: Attach
  36 +# BreakBeforeTernaryOperators: true
  37 +# BreakConstructorInitializersBeforeComma: false
  38 +# BreakAfterJavaFieldAnnotations: false
  39 +# BreakStringLiterals: true
  40 +ColumnLimit: 120
  41 +# CommentPragmas: '^ IWYU pragma:'
  42 +# ConstructorInitializerAllOnOneLineOrOnePerLine: false
  43 +# ConstructorInitializerIndentWidth: 4
  44 +# ContinuationIndentWidth: 4
  45 +# Cpp11BracedListStyle: true
  46 +# DerivePointerAlignment: false
  47 +# DisableFormat: false
  48 +# ExperimentalAutoDetectBinPacking: false
  49 +# ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
  50 +# IncludeIsMainRegex: '$'
  51 +# IndentCaseLabels: false
  52 +IndentWidth: 4
  53 +# IndentWrappedFunctionNames: false
  54 +# JavaScriptQuotes: Leave
  55 +# JavaScriptWrapImports: true
  56 +# KeepEmptyLinesAtTheStartOfBlocks: true
  57 +# MacroBlockBegin: ''
  58 +# MacroBlockEnd: ''
  59 +# MaxEmptyLinesToKeep: 1
  60 +# NamespaceIndentation: None
  61 +# ObjCBlockIndentWidth: 2
  62 +# ObjCSpaceAfterProperty: false
  63 +# ObjCSpaceBeforeProtocolList: true
  64 +# PenaltyBreakBeforeFirstCallParameter: 19
  65 +# PenaltyBreakComment: 300
  66 +# PenaltyBreakFirstLessLess: 120
  67 +# PenaltyBreakString: 1000
  68 +# PenaltyExcessCharacter: 1000000
  69 +# PenaltyReturnTypeOnItsOwnLine: 60
  70 +# PointerAlignment: Right
  71 +# ReflowComments: true
  72 +SortIncludes: false
  73 +# SpaceAfterCStyleCast: false
  74 +# SpaceAfterTemplateKeyword: true
  75 +# SpaceBeforeAssignmentOperators: true
  76 +SpaceBeforeParens: Never
  77 +# SpaceInEmptyParentheses: false
  78 +# SpacesBeforeTrailingComments: 1
  79 +# SpacesInAngles: false
  80 +# SpacesInContainerLiterals: true
  81 +# SpacesInCStyleCastParentheses: false
  82 +# SpacesInParentheses: false
  83 +# SpacesInSquareBrackets: false
  84 +Standard: Cpp11
  85 +TabWidth: 4
  86 +UseTab: Never
... ...
examples/try.cpp
1 1 #include "CLI/CLI.hpp"
2 2  
3   -
4   -int main (int argc, char** argv) {
  3 +int main(int argc, char **argv) {
5 4  
6 5 CLI::App app("K3Pi goofit fitter");
7 6  
8 7 std::string file;
9   - CLI::Option* opt = app.add_option("-f,--file,file", file, "File name");
10   -
  8 + CLI::Option *opt = app.add_option("-f,--file,file", file, "File name");
  9 +
11 10 int count;
12   - CLI::Option* copt = app.add_flag("-c,--count", count, "Counter");
  11 + CLI::Option *copt = app.add_flag("-c,--count", count, "Counter");
13 12  
14   - double value;// = 3.14;
  13 + double value; // = 3.14;
15 14 app.add_option("-d,--double", value, "Some Value");
16 15  
17 16 try {
18 17 app.parse(argc, argv);
19   - } catch (const CLI::Error &e) {
  18 + } catch(const CLI::Error &e) {
20 19 return app.exit(e);
21 20 }
22 21  
23   - std::cout << "Working on file: " << file
24   - << ", direct count: " << app.count("--file")
25   - << ", opt count: " << opt->count()
26   - << std::endl;
27   - std::cout << "Working on count: " << count
28   - << ", direct count: " << app.count("--count")
29   - << ", opt count: " << copt->count()
30   - << std::endl;
  22 + std::cout << "Working on file: " << file << ", direct count: " << app.count("--file")
  23 + << ", opt count: " << opt->count() << std::endl;
  24 + std::cout << "Working on count: " << count << ", direct count: " << app.count("--count")
  25 + << ", opt count: " << copt->count() << std::endl;
31 26 std::cout << "Some value: " << value << std::endl;
32 27  
33 28 return 0;
... ...
examples/try1.cpp
1 1 #include "CLI/CLI.hpp"
2 2  
3   -
4   -int main (int argc, char** argv) {
  3 +int main(int argc, char **argv) {
5 4  
6 5 CLI::App app("K3Pi goofit fitter");
7 6 app.add_flag("--random", "Some random flag");
8   - CLI::App* start = app.add_subcommand("start", "A great subcommand");
9   - CLI::App* stop = app.add_subcommand("stop", "Do you really want to stop?");
  7 + CLI::App *start = app.add_subcommand("start", "A great subcommand");
  8 + CLI::App *stop = app.add_subcommand("stop", "Do you really want to stop?");
10 9  
11 10 std::string file;
12 11 start->add_option("-f,--file", file, "File name");
13   -
14   - CLI::Option* s = stop->add_flag("-c,--count", "Counter");
  12 +
  13 + CLI::Option *s = stop->add_flag("-c,--count", "Counter");
15 14  
16 15 try {
17 16 app.parse(argc, argv);
18   - } catch (const CLI::Error &e) {
  17 + } catch(const CLI::Error &e) {
19 18 return app.exit(e);
20 19 }
21 20  
... ...
examples/try2.cpp
1 1 #include "CLI/CLI.hpp"
2 2 #include "CLI/Timer.hpp"
3 3  
4   -
5   -int main (int argc, char** argv) {
  4 +int main(int argc, char **argv) {
6 5 CLI::AutoTimer("This is a timer");
7 6  
8 7 CLI::App app("K3Pi goofit fitter");
9 8  
10 9 std::string file;
11   - CLI::Option* opt = app.add_option("-f,--file,file", file, "File name")
12   - ->required()->group("Important");
13   -
  10 + CLI::Option *opt = app.add_option("-f,--file,file", file, "File name")->required()->group("Important");
  11 +
14 12 int count;
15   - CLI::Option* copt = app.add_flag("-c,--count", count, "Counter")
16   - ->required()->group("Important");
  13 + CLI::Option *copt = app.add_flag("-c,--count", count, "Counter")->required()->group("Important");
17 14  
18   - double value;// = 3.14;
19   - app.add_option("-d,--double", value, "Some Value")
20   - ->group("Other");
  15 + double value; // = 3.14;
  16 + app.add_option("-d,--double", value, "Some Value")->group("Other");
21 17  
22 18 try {
23 19 app.parse(argc, argv);
24   - } catch (const CLI::Error &e) {
  20 + } catch(const CLI::Error &e) {
25 21 return app.exit(e);
26 22 }
27 23  
28   - std::cout << "Working on file: " << file
29   - << ", direct count: " << app.count("--file")
30   - << ", opt count: " << opt->count()
31   - << std::endl;
32   - std::cout << "Working on count: " << count
33   - << ", direct count: " << app.count("--count")
34   - << ", opt count: " << copt->count()
35   - << std::endl;
  24 + std::cout << "Working on file: " << file << ", direct count: " << app.count("--file")
  25 + << ", opt count: " << opt->count() << std::endl;
  26 + std::cout << "Working on count: " << count << ", direct count: " << app.count("--count")
  27 + << ", opt count: " << copt->count() << std::endl;
36 28 std::cout << "Some value: " << value << std::endl;
37 29  
38 30 return 0;
... ...
include/CLI/App.hpp
... ... @@ -15,7 +15,6 @@
15 15 #include <utility>
16 16 #include <vector>
17 17  
18   -
19 18 // CLI Library includes
20 19 #include "CLI/Error.hpp"
21 20 #include "CLI/Ini.hpp"
... ... @@ -27,13 +26,12 @@
27 26 namespace CLI {
28 27  
29 28 namespace detail {
30   -enum class Classifer {NONE, POSITIONAL_MARK, SHORT, LONG, SUBCOMMAND};
  29 +enum class Classifer { NONE, POSITIONAL_MARK, SHORT, LONG, SUBCOMMAND };
31 30 struct AppFriend;
32 31 } // namespace detail
33 32  
34 33 class App;
35 34  
36   -
37 35 using App_p = std::unique_ptr<App>;
38 36  
39 37 /// Creates a command line program, with very few defaults.
... ... @@ -43,21 +41,21 @@ using App_p = std::unique_ptr&lt;App&gt;;
43 41 class App {
44 42 friend Option;
45 43 friend detail::AppFriend;
46   -protected:
47   -
  44 +
  45 + protected:
48 46 // This library follows the Google style guide for member names ending in underscores
49 47  
50 48 /// @name Basics
51 49 ///@{
52   -
  50 +
53 51 /// Subcommand name or program name (from parser)
54   - std::string name_ {"program"};
55   -
  52 + std::string name_{"program"};
  53 +
56 54 /// Description of the current program/subcommand
57 55 std::string description_;
58 56  
59 57 /// If true, allow extra arguments (ie, don't throw an error).
60   - bool allow_extras_ {false};
  58 + bool allow_extras_{false};
61 59  
62 60 /// This is a function that runs when complete. Great for subcommands. Can throw.
63 61 std::function<void()> callback_;
... ... @@ -68,9 +66,9 @@ protected:
68 66  
69 67 /// The list of options, stored locally
70 68 std::vector<Option_p> options_;
71   -
  69 +
72 70 /// A pointer to the help flag if there is one
73   - Option* help_ptr_ {nullptr};
  71 + Option *help_ptr_{nullptr};
74 72  
75 73 ///@}
76 74 /// @name Parsing
... ... @@ -79,28 +77,28 @@ protected:
79 77 using missing_t = std::vector<std::pair<detail::Classifer, std::string>>;
80 78  
81 79 /// Pair of classifier, string for missing options. (extra detail is removed on returning from parse)
82   - ///
  80 + ///
83 81 /// This is faster and cleaner than storing just a list of strings and reparsing. This may contain the -- separator.
84 82 missing_t missing_;
85 83  
86 84 ///@}
87 85 /// @name Subcommands
88 86 ///@{
89   -
  87 +
90 88 /// Storage for subcommand list
91 89 std::vector<App_p> subcommands_;
92 90  
93 91 /// If true, the program name is not case sensitive
94   - bool ignore_case_ {false};
  92 + bool ignore_case_{false};
95 93  
96 94 /// Allow subcommand fallthrough, so that parent commands can collect commands after subcommand.
97   - bool fallthrough_ {false};
  95 + bool fallthrough_{false};
98 96  
99 97 /// A pointer to the parent if this is a subcommand
100   - App* parent_ {nullptr};
  98 + App *parent_{nullptr};
101 99  
102 100 /// True if this command/subcommand was parsed
103   - bool parsed_ {false};
  101 + bool parsed_{false};
104 102  
105 103 /// -1 for 1 or more, 0 for not required, # for exact number required
106 104 int require_subcommand_ = 0;
... ... @@ -112,53 +110,47 @@ protected:
112 110 /// The name of the connected config file
113 111 std::string config_name_;
114 112  
115   - /// True if ini is required (throws if not present), if false simply keep going.
116   - bool config_required_ {false};
  113 + /// True if ini is required (throws if not present), if false simply keep going.
  114 + bool config_required_{false};
117 115  
118 116 /// Pointer to the config option
119   - Option* config_ptr_ {nullptr};
120   -
  117 + Option *config_ptr_{nullptr};
121 118  
122 119 ///@}
123   -
  120 +
124 121 /// Special private constructor for subcommand
125   - App(std::string description_, bool help, detail::enabler)
126   - : description_(std::move(description_)) {
  122 + App(std::string description_, bool help, detail::enabler) : description_(std::move(description_)) {
127 123  
128 124 if(help)
129 125 help_ptr_ = add_flag("-h,--help", "Print this help message and exit");
130   -
131 126 }
132 127  
133   -public:
  128 + public:
134 129 /// @name Basic
135 130 ///@{
136 131  
137 132 /// Create a new program. Pass in the same arguments as main(), along with a help string.
138   - App(std::string description_="", bool help=true)
139   - : App(description_, help, detail::dummy) {
140   -
141   - }
  133 + App(std::string description_ = "", bool help = true) : App(description_, help, detail::dummy) {}
142 134  
143 135 /// Set a callback for the end of parsing.
144   - ///
  136 + ///
145 137 /// Due to a bug in c++11,
146 138 /// it is not possible to overload on std::function (fixed in c++14
147 139 /// and backported to c++11 on newer compilers). Use capture by reference
148 140 /// to get a pointer to App if needed.
149   - App* set_callback(std::function<void()> callback) {
  141 + App *set_callback(std::function<void()> callback) {
150 142 callback_ = callback;
151 143 return this;
152 144 }
153 145  
154 146 /// Remove the error when extras are left over on the command line.
155   - App* allow_extras (bool allow=true) {
  147 + App *allow_extras(bool allow = true) {
156 148 allow_extras_ = allow;
157 149 return this;
158 150 }
159 151  
160 152 /// Ignore case. Subcommand inherit value.
161   - App* ignore_case(bool value = true) {
  153 + App *ignore_case(bool value = true) {
162 154 ignore_case_ = value;
163 155 if(parent_ != nullptr) {
164 156 for(const auto &subc : parent_->subcommands_) {
... ... @@ -170,81 +162,72 @@ public:
170 162 }
171 163  
172 164 /// Check to see if this subcommand was parsed, true only if received on command line.
173   - bool parsed() const {return parsed_;}
  165 + bool parsed() const { return parsed_; }
174 166  
175 167 /// Check to see if this subcommand was parsed, true only if received on command line.
176 168 /// This allows the subcommand to be directly checked.
177   - operator bool () const { return parsed_;}
  169 + operator bool() const { return parsed_; }
178 170  
179 171 /// Require a subcommand to be given (does not affect help call)
180 172 /// Does not return a pointer since it is supposed to be called on the main App.
181   - App* require_subcommand(int value = -1) {
  173 + App *require_subcommand(int value = -1) {
182 174 require_subcommand_ = value;
183 175 return this;
184 176 }
185 177  
186 178 /// Stop subcommand fallthrough, so that parent commands cannot collect commands after subcommand.
187 179 /// Default from parent, usually set on parent.
188   - App* fallthrough(bool value=true) {
  180 + App *fallthrough(bool value = true) {
189 181 fallthrough_ = value;
190 182 return this;
191 183 }
192 184  
193   -
194 185 ///@}
195 186 /// @name Adding options
196 187 ///@{
197   -
  188 +
198 189 /// Add an option, will automatically understand the type for common types.
199 190 ///
200 191 /// To use, create a variable with the expected type, and pass it in after the name.
201 192 /// After start is called, you can use count to see if the value was passed, and
202 193 /// the value will be initialized properly. Numbers, vectors, and strings are supported.
203   - ///
204   - /// ->required(), ->default, and the validators are options,
  194 + ///
  195 + /// ->required(), ->default, and the validators are options,
205 196 /// The positional options take an optional number of arguments.
206   - ///
  197 + ///
207 198 /// For example,
208   - ///
  199 + ///
209 200 /// std::string filename;
210 201 /// program.add_option("filename", filename, "description of filename");
211 202 ///
212   - Option* add_option(
213   - std::string name,
214   - callback_t callback,
215   - std::string description="",
216   - bool defaulted=false
217   - ) {
  203 + Option *add_option(std::string name, callback_t callback, std::string description = "", bool defaulted = false) {
218 204 Option myopt{name, description, callback, defaulted, this};
219 205  
220   - if(std::find_if(std::begin(options_), std::end(options_),
221   - [&myopt](const Option_p &v){return *v == myopt;}) == std::end(options_)) {
  206 + if(std::find_if(std::begin(options_), std::end(options_), [&myopt](const Option_p &v) {
  207 + return *v == myopt;
  208 + }) == std::end(options_)) {
222 209 options_.emplace_back();
223   - Option_p& option = options_.back();
  210 + Option_p &option = options_.back();
224 211 option.reset(new Option(name, description, callback, defaulted, this));
225 212 return option.get();
226 213 } else
227 214 throw OptionAlreadyAdded(myopt.get_name());
228   -
229 215 }
230 216  
231 217 /// Add option for non-vectors
232   - template<typename T, enable_if_t<!is_vector<T>::value, detail::enabler> = detail::dummy>
233   - Option* add_option(
234   - std::string name,
235   - T &variable, ///< The variable to set
236   - std::string description="",
237   - bool defaulted=false
238   - ) {
239   -
240   -
241   - CLI::callback_t fun = [&variable](CLI::results_t res){
242   - if(res.size()!=1)
  218 + template <typename T, enable_if_t<!is_vector<T>::value, detail::enabler> = detail::dummy>
  219 + Option *add_option(std::string name,
  220 + T &variable, ///< The variable to set
  221 + std::string description = "",
  222 + bool defaulted = false) {
  223 +
  224 + CLI::callback_t fun = [&variable](CLI::results_t res) {
  225 + if(res.size() != 1)
243 226 return false;
244 227 return detail::lexical_cast(res[0], variable);
245 228 };
246 229  
247   - Option* opt = add_option(name, fun, description, defaulted);
  230 + Option *opt = add_option(name, fun, description, defaulted);
248 231 opt->set_custom_option(detail::type_name<T>());
249 232 if(defaulted) {
250 233 std::stringstream out;
... ... @@ -255,15 +238,13 @@ public:
255 238 }
256 239  
257 240 /// Add option for vectors
258   - template<typename T>
259   - Option* add_option(
260   - std::string name,
261   - std::vector<T> &variable, ///< The variable vector to set
262   - std::string description="",
263   - bool defaulted=false
264   - ) {
265   -
266   - CLI::callback_t fun = [&variable](CLI::results_t res){
  241 + template <typename T>
  242 + Option *add_option(std::string name,
  243 + std::vector<T> &variable, ///< The variable vector to set
  244 + std::string description = "",
  245 + bool defaulted = false) {
  246 +
  247 + CLI::callback_t fun = [&variable](CLI::results_t res) {
267 248 bool retval = true;
268 249 variable.clear();
269 250 for(const auto &a : res) {
... ... @@ -273,7 +254,7 @@ public:
273 254 return variable.size() > 0 && retval;
274 255 };
275 256  
276   - Option* opt = add_option(name, fun, description, defaulted);
  257 + Option *opt = add_option(name, fun, description, defaulted);
277 258 opt->set_custom_option(detail::type_name<T>(), -1, true);
278 259 if(defaulted)
279 260 opt->set_default_val("[" + detail::join(variable) + "]");
... ... @@ -281,15 +262,10 @@ public:
281 262 }
282 263  
283 264 /// Add option for flag
284   - Option* add_flag(
285   - std::string name,
286   - std::string description=""
287   - ) {
288   - CLI::callback_t fun = [](CLI::results_t){
289   - return true;
290   - };
291   -
292   - Option* opt = add_option(name, fun, description, false);
  265 + Option *add_flag(std::string name, std::string description = "") {
  266 + CLI::callback_t fun = [](CLI::results_t) { return true; };
  267 +
  268 + Option *opt = add_option(name, fun, description, false);
293 269 if(opt->get_positional())
294 270 throw IncorrectConstruction("Flags cannot be positional");
295 271 opt->set_custom_option("", 0);
... ... @@ -297,21 +273,19 @@ public:
297 273 }
298 274  
299 275 /// Add option for flag integer
300   - template<typename T,
301   - enable_if_t<std::is_integral<T>::value && !is_bool<T>::value, detail::enabler> = detail::dummy>
302   - Option* add_flag(
303   - std::string name,
304   - T &count, ///< A varaible holding the count
305   - std::string description=""
306   - ) {
  276 + template <typename T,
  277 + enable_if_t<std::is_integral<T>::value && !is_bool<T>::value, detail::enabler> = detail::dummy>
  278 + Option *add_flag(std::string name,
  279 + T &count, ///< A varaible holding the count
  280 + std::string description = "") {
307 281  
308 282 count = 0;
309   - CLI::callback_t fun = [&count](CLI::results_t res){
  283 + CLI::callback_t fun = [&count](CLI::results_t res) {
310 284 count = static_cast<T>(res.size());
311 285 return true;
312 286 };
313   -
314   - Option* opt = add_option(name, fun, description, false);
  287 +
  288 + Option *opt = add_option(name, fun, description, false);
315 289 if(opt->get_positional())
316 290 throw IncorrectConstruction("Flags cannot be positional");
317 291 opt->set_custom_option("", 0);
... ... @@ -319,40 +293,34 @@ public:
319 293 }
320 294  
321 295 /// Bool version only allows the flag once
322   - template<typename T,
323   - enable_if_t<is_bool<T>::value, detail::enabler> = detail::dummy>
324   - Option* add_flag(
325   - std::string name,
326   - T &count, ///< A varaible holding true if passed
327   - std::string description=""
328   - ) {
  296 + template <typename T, enable_if_t<is_bool<T>::value, detail::enabler> = detail::dummy>
  297 + Option *add_flag(std::string name,
  298 + T &count, ///< A varaible holding true if passed
  299 + std::string description = "") {
329 300  
330 301 count = false;
331   - CLI::callback_t fun = [&count](CLI::results_t res){
  302 + CLI::callback_t fun = [&count](CLI::results_t res) {
332 303 count = true;
333 304 return res.size() == 1;
334 305 };
335   -
336   - Option* opt = add_option(name, fun, description, false);
  306 +
  307 + Option *opt = add_option(name, fun, description, false);
337 308 if(opt->get_positional())
338 309 throw IncorrectConstruction("Flags cannot be positional");
339 310 opt->set_custom_option("", 0);
340 311 return opt;
341 312 }
342 313  
343   -
344 314 /// Add set of options
345   - template<typename T>
346   - Option* add_set(
347   - std::string name,
348   - T &member, ///< The selected member of the set
349   - std::set<T> options, ///< The set of posibilities
350   - std::string description="",
351   - bool defaulted=false
352   - ) {
353   -
354   - CLI::callback_t fun = [&member, options](CLI::results_t res){
355   - if(res.size()!=1) {
  315 + template <typename T>
  316 + Option *add_set(std::string name,
  317 + T &member, ///< The selected member of the set
  318 + std::set<T> options, ///< The set of posibilities
  319 + std::string description = "",
  320 + bool defaulted = false) {
  321 +
  322 + CLI::callback_t fun = [&member, options](CLI::results_t res) {
  323 + if(res.size() != 1) {
356 324 return false;
357 325 }
358 326 bool retval = detail::lexical_cast(res[0], member);
... ... @@ -361,7 +329,7 @@ public:
361 329 return std::find(std::begin(options), std::end(options), member) != std::end(options);
362 330 };
363 331  
364   - Option* opt = add_option(name, fun, description, defaulted);
  332 + Option *opt = add_option(name, fun, description, defaulted);
365 333 std::string typeval = detail::type_name<T>();
366 334 typeval += " in {" + detail::join(options) + "}";
367 335 opt->set_custom_option(typeval);
... ... @@ -374,21 +342,20 @@ public:
374 342 }
375 343  
376 344 /// Add set of options, string only, ignore case
377   - Option* add_set_ignore_case(
378   - std::string name,
379   - std::string &member, ///< The selected member of the set
380   - std::set<std::string> options, ///< The set of posibilities
381   - std::string description="",
382   - bool defaulted=false
383   - ) {
384   -
385   - CLI::callback_t fun = [&member, options](CLI::results_t res){
386   - if(res.size()!=1) {
  345 + Option *add_set_ignore_case(std::string name,
  346 + std::string &member, ///< The selected member of the set
  347 + std::set<std::string> options, ///< The set of posibilities
  348 + std::string description = "",
  349 + bool defaulted = false) {
  350 +
  351 + CLI::callback_t fun = [&member, options](CLI::results_t res) {
  352 + if(res.size() != 1) {
387 353 return false;
388 354 }
389 355 member = detail::to_lower(res[0]);
390   - auto iter = std::find_if(std::begin(options), std::end(options),
391   - [&member](std::string val){return detail::to_lower(val) == member;});
  356 + auto iter = std::find_if(std::begin(options), std::end(options), [&member](std::string val) {
  357 + return detail::to_lower(val) == member;
  358 + });
392 359 if(iter == std::end(options))
393 360 return false;
394 361 else {
... ... @@ -397,7 +364,7 @@ public:
397 364 }
398 365 };
399 366  
400   - Option* opt = add_option(name, fun, description, defaulted);
  367 + Option *opt = add_option(name, fun, description, defaulted);
401 368 std::string typeval = detail::type_name<std::string>();
402 369 typeval += " in {" + detail::join(options) + "}";
403 370 opt->set_custom_option(typeval);
... ... @@ -408,94 +375,93 @@ public:
408 375 }
409 376  
410 377 /// Add a complex number
411   - template<typename T>
412   - Option* add_complex(
413   - std::string name, T& variable,
414   - std::string description="", bool defaulted=false,
415   - std::string label="COMPLEX") {
416   - CLI::callback_t fun = [&variable](results_t res){
417   - if(res.size()!=2)
418   - return false;
419   - double x,y;
420   - bool worked = detail::lexical_cast(res[0], x)
421   - && detail::lexical_cast(res[1], y);
422   - if(worked)
423   - variable = T(x,y);
424   - return worked;
425   - };
426   -
427   - CLI::Option* opt = add_option(name, fun, description, defaulted);
428   - opt->set_custom_option(label, 2);
429   - if(defaulted) {
430   - std::stringstream out;
431   - out << variable;
432   - opt->set_default_val(out.str());
433   - }
434   - return opt;
435   - }
  378 + template <typename T>
  379 + Option *add_complex(std::string name,
  380 + T &variable,
  381 + std::string description = "",
  382 + bool defaulted = false,
  383 + std::string label = "COMPLEX") {
  384 + CLI::callback_t fun = [&variable](results_t res) {
  385 + if(res.size() != 2)
  386 + return false;
  387 + double x, y;
  388 + bool worked = detail::lexical_cast(res[0], x) && detail::lexical_cast(res[1], y);
  389 + if(worked)
  390 + variable = T(x, y);
  391 + return worked;
  392 + };
436 393  
  394 + CLI::Option *opt = add_option(name, fun, description, defaulted);
  395 + opt->set_custom_option(label, 2);
  396 + if(defaulted) {
  397 + std::stringstream out;
  398 + out << variable;
  399 + opt->set_default_val(out.str());
  400 + }
  401 + return opt;
  402 + }
437 403  
438 404 /// Add a configuration ini file option
439   - Option* add_config(std::string name="--config",
440   - std::string default_filename="",
441   - std::string help="Read an ini file",
442   - bool required=false) {
  405 + Option *add_config(std::string name = "--config",
  406 + std::string default_filename = "",
  407 + std::string help = "Read an ini file",
  408 + bool required = false) {
443 409  
444 410 // Remove existing config if present
445 411 if(config_ptr_ != nullptr)
446 412 remove_option(config_ptr_);
447 413 config_name_ = default_filename;
448 414 config_required_ = required;
449   - config_ptr_ = add_option(name, config_name_, help, default_filename!="");
  415 + config_ptr_ = add_option(name, config_name_, help, default_filename != "");
450 416 return config_ptr_;
451 417 }
452 418  
453 419 /// Removes an option from the App. Takes an option pointer. Returns true if found and removed.
454   - bool remove_option(Option* opt) {
455   - auto iterator = std::find_if(std::begin(options_), std::end(options_),
456   - [opt](const Option_p &v){return v.get() == opt;});
457   - if (iterator != std::end(options_)) {
  420 + bool remove_option(Option *opt) {
  421 + auto iterator =
  422 + std::find_if(std::begin(options_), std::end(options_), [opt](const Option_p &v) { return v.get() == opt; });
  423 + if(iterator != std::end(options_)) {
458 424 options_.erase(iterator);
459 425 return true;
460 426 }
461 427 return false;
462 428 }
463   -
  429 +
464 430 ///@}
465 431 /// @name Subcommmands
466 432 ///@{
467 433  
468 434 /// Add a subcommand. Like the constructor, you can override the help message addition by setting help=false
469   - App* add_subcommand(std::string name, std::string description="", bool help=true) {
  435 + App *add_subcommand(std::string name, std::string description = "", bool help = true) {
470 436 subcommands_.emplace_back(new App(description, help, detail::dummy));
471 437 subcommands_.back()->name_ = name;
472 438 subcommands_.back()->allow_extras();
473 439 subcommands_.back()->parent_ = this;
474 440 subcommands_.back()->ignore_case_ = ignore_case_;
475 441 subcommands_.back()->fallthrough_ = fallthrough_;
476   - for(const auto& subc : subcommands_)
  442 + for(const auto &subc : subcommands_)
477 443 if(subc.get() != subcommands_.back().get())
478   - if(subc->check_name(subcommands_.back()->name_) || subcommands_.back()->check_name(subc->name_))
  444 + if(subc->check_name(subcommands_.back()->name_) || subcommands_.back()->check_name(subc->name_))
479 445 throw OptionAlreadyAdded(subc->name_);
480 446 return subcommands_.back().get();
481 447 }
482 448  
483 449 /// Check to see if a subcommand is part of this command (doesn't have to be in command line)
484   - App* get_subcommand(App* subcom) const {
  450 + App *get_subcommand(App *subcom) const {
485 451 for(const App_p &subcomptr : subcommands_)
486 452 if(subcomptr.get() == subcom)
487 453 return subcom;
488 454 throw CLI::OptionNotFound(subcom->get_name());
489 455 }
490   -
  456 +
491 457 /// Check to see if a subcommand is part of this command (text version)
492   - App* get_subcommand(std::string subcom) const {
  458 + App *get_subcommand(std::string subcom) const {
493 459 for(const App_p &subcomptr : subcommands_)
494 460 if(subcomptr->check_name(subcom))
495 461 return subcomptr.get();
496 462 throw CLI::OptionNotFound(subcom);
497 463 }
498   -
  464 +
499 465 ///@}
500 466 /// @name Extras for subclassing
501 467 ///@{
... ... @@ -514,15 +480,14 @@ public:
514 480 std::vector<std::string> parse(int argc, char **argv) {
515 481 name_ = argv[0];
516 482 std::vector<std::string> args;
517   - for(int i=argc-1; i>0; i--)
  483 + for(int i = argc - 1; i > 0; i--)
518 484 args.emplace_back(argv[i]);
519 485 return parse(args);
520   -
521 486 }
522 487  
523 488 /// The real work is done here. Expects a reversed vector.
524 489 /// Changes the vector to the remaining options.
525   - std::vector<std::string>& parse(std::vector<std::string> &args) {
  490 + std::vector<std::string> &parse(std::vector<std::string> &args) {
526 491 _validate();
527 492 _parse(args);
528 493 run_callback();
... ... @@ -530,7 +495,7 @@ public:
530 495 }
531 496  
532 497 /// Print a nice error message and return the exit code
533   - int exit(const Error& e) const {
  498 + int exit(const Error &e) const {
534 499 if(e.exit_code != static_cast<int>(ExitCodes::Success)) {
535 500 std::cerr << "ERROR: ";
536 501 std::cerr << e.what() << std::endl;
... ... @@ -572,32 +537,30 @@ public:
572 537 }
573 538  
574 539 /// Get a subcommand pointer list to the currently selected subcommands (after parsing)
575   - std::vector<App*> get_subcommands() const {
576   - std::vector<App*> subcomms;
  540 + std::vector<App *> get_subcommands() const {
  541 + std::vector<App *> subcomms;
577 542 for(const App_p &subcomptr : subcommands_)
578 543 if(subcomptr->parsed_)
579 544 subcomms.push_back(subcomptr.get());
580 545 return subcomms;
581 546 }
582 547  
583   -
584 548 /// Check to see if given subcommand was selected
585   - bool got_subcommand(App* subcom) const {
  549 + bool got_subcommand(App *subcom) const {
586 550 // get subcom needed to verify that this was a real subcommand
587 551 return get_subcommand(subcom)->parsed_;
588 552 }
589 553  
590 554 /// Check with name instead of pointer to see if subcommand was selected
591   - bool got_subcommand(std::string name) const {
592   - return get_subcommand(name)->parsed_;
593   - }
594   -
  555 + bool got_subcommand(std::string name) const { return get_subcommand(name)->parsed_; }
  556 +
595 557 ///@}
596 558 /// @name Help
597 559 ///@{
598 560  
599   - /// Produce a string that could be read in as a config of the current values of the App. Set default_also to include default arguments. Prefix will add a string to the beginning of each option.
600   - std::string config_to_str(bool default_also=false, std::string prefix="") const {
  561 + /// Produce a string that could be read in as a config of the current values of the App. Set default_also to include
  562 + /// default arguments. Prefix will add a string to the beginning of each option.
  563 + std::string config_to_str(bool default_also = false, std::string prefix = "") const {
601 564 std::stringstream out;
602 565 for(const Option_p &opt : options_) {
603 566  
... ... @@ -615,19 +578,18 @@ public:
615 578 // If the option has a default and is requested by optional argument
616 579 else if(default_also && opt->defaultval_ != "")
617 580 out << name << "=" << opt->defaultval_ << std::endl;
618   - // Flag, one passed
  581 + // Flag, one passed
619 582 } else if(opt->count() == 1) {
620 583 out << name << "=true" << std::endl;
621 584  
622   - // Flag, multiple passed
  585 + // Flag, multiple passed
623 586 } else if(opt->count() > 1) {
624 587 out << name << "=" << opt->count() << std::endl;
625 588  
626   - // Flag, not present
  589 + // Flag, not present
627 590 } else if(opt->count() == 0 && default_also && opt.get() != get_help_ptr()) {
628 591 out << name << "=false" << std::endl;
629 592 }
630   -
631 593 }
632 594 }
633 595 for(const App_p &subcom : subcommands_)
... ... @@ -636,7 +598,7 @@ public:
636 598 }
637 599  
638 600 /// Makes a help message, with a column wid for column 1
639   - std::string help(size_t wid=30, std::string prev="") const {
  601 + std::string help(size_t wid = 30, std::string prev = "") const {
640 602 // Delegate to subcommand if needed
641 603 if(prev == "")
642 604 prev = name_;
... ... @@ -650,7 +612,7 @@ public:
650 612 std::stringstream out;
651 613 out << description_ << std::endl;
652 614 out << "Usage: " << prev;
653   -
  615 +
654 616 // Check for options_
655 617 bool npos = false;
656 618 std::set<std::string> groups;
... ... @@ -665,15 +627,15 @@ public:
665 627 out << " [OPTIONS]";
666 628  
667 629 // Positionals
668   - bool pos=false;
  630 + bool pos = false;
669 631 for(const Option_p &opt : options_)
670 632 if(opt->get_positional()) {
671 633 // A hidden positional should still show up in the usage statement
672   - //if(detail::to_lower(opt->get_group()) == "hidden")
  634 + // if(detail::to_lower(opt->get_group()) == "hidden")
673 635 // continue;
674 636 out << " " << opt->help_positional();
675 637 if(opt->_has_help_positional())
676   - pos=true;
  638 + pos = true;
677 639 }
678 640  
679 641 if(!subcommands_.empty()) {
... ... @@ -695,20 +657,17 @@ public:
695 657 detail::format_help(out, opt->help_pname(), opt->get_description(), wid);
696 658 }
697 659 out << std::endl;
698   -
699 660 }
700 661  
701   -
702 662 // Options
703 663 if(npos) {
704   - for (const std::string& group : groups) {
  664 + for(const std::string &group : groups) {
705 665 if(detail::to_lower(group) == "hidden")
706 666 continue;
707 667 out << group << ":" << std::endl;
708 668 for(const Option_p &opt : options_) {
709 669 if(opt->nonpositional() && opt->get_group() == group)
710 670 detail::format_help(out, opt->help_name(), opt->get_description(), wid);
711   -
712 671 }
713 672 out << std::endl;
714 673 }
... ... @@ -728,28 +687,18 @@ public:
728 687 ///@{
729 688  
730 689 /// Get a pointer to the help flag.
731   - Option* get_help_ptr() {
732   - return help_ptr_;
733   - }
  690 + Option *get_help_ptr() { return help_ptr_; }
734 691  
735 692 /// Get a pointer to the help flag. (const)
736   - const Option* get_help_ptr() const {
737   - return help_ptr_;
738   - }
  693 + const Option *get_help_ptr() const { return help_ptr_; }
739 694  
740 695 /// Get a pointer to the config option.
741   - Option* get_config_ptr() {
742   - return config_ptr_;
743   - }
  696 + Option *get_config_ptr() { return config_ptr_; }
744 697  
745 698 /// Get a pointer to the config option. (const)
746   - const Option* get_config_ptr() const {
747   - return config_ptr_;
748   - }
  699 + const Option *get_config_ptr() const { return config_ptr_; }
749 700 /// Get the name of the current app
750   - std::string get_name() const {
751   - return name_;
752   - }
  701 + std::string get_name() const { return name_; }
753 702  
754 703 /// Check the name, case insensitive if set
755 704 bool check_name(std::string name_to_check) const {
... ... @@ -764,24 +713,22 @@ public:
764 713  
765 714 ///@}
766 715  
767   -
768   -protected:
769   -
  716 + protected:
770 717 /// Check the options to make sure there are no conficts.
771 718 ///
772 719 /// Currenly checks to see if mutiple positionals exist with -1 args
773 720 void _validate() const {
774   - auto count = std::count_if(std::begin(options_), std::end(options_),
775   - [](const Option_p& opt){return opt->get_expected() == -1 && opt->get_positional();});
  721 + auto count = std::count_if(std::begin(options_), std::end(options_), [](const Option_p &opt) {
  722 + return opt->get_expected() == -1 && opt->get_positional();
  723 + });
776 724 if(count > 1)
777 725 throw InvalidError(name_ + ": Too many positional arguments with unlimited expected args");
778   - for(const App_p& app : subcommands_)
  726 + for(const App_p &app : subcommands_)
779 727 app->_validate();
780 728 }
781 729  
782   -
783 730 /// Return missing from the master
784   - missing_t* missing() {
  731 + missing_t *missing() {
785 732 if(parent_ != nullptr)
786 733 return parent_->missing();
787 734 return &missing_;
... ... @@ -792,7 +739,7 @@ protected:
792 739 pre_callback();
793 740 if(callback_)
794 741 callback_();
795   - for(App* subc : get_subcommands()) {
  742 + for(App *subc : get_subcommands()) {
796 743 subc->run_callback();
797 744 }
798 745 }
... ... @@ -807,7 +754,6 @@ protected:
807 754 return false;
808 755 }
809 756  
810   -
811 757 /// Selects a Classifer enum based on the type of the current argument
812 758 detail::Classifer _recognize(const std::string &current) const {
813 759 std::string dummy1, dummy2;
... ... @@ -823,23 +769,21 @@ protected:
823 769 return detail::Classifer::NONE;
824 770 }
825 771  
826   -
827 772 /// Internal parse function
828 773 void _parse(std::vector<std::string> &args) {
829 774 parsed_ = true;
830 775 bool positional_only = false;
831   -
  776 +
832 777 while(!args.empty()) {
833 778 _parse_single(args, positional_only);
834 779 }
835 780  
836   - if (help_ptr_ != nullptr && help_ptr_->count() > 0) {
  781 + if(help_ptr_ != nullptr && help_ptr_->count() > 0) {
837 782 throw CallForHelp();
838 783 }
839 784  
840   -
841 785 // Process an INI file
842   - if (config_ptr_ != nullptr && config_name_ != "") {
  786 + if(config_ptr_ != nullptr && config_name_ != "") {
843 787 try {
844 788 std::vector<detail::ini_ret_t> values = detail::parse_ini(config_name_);
845 789 while(!values.empty()) {
... ... @@ -847,16 +791,15 @@ protected:
847 791 throw ExtrasINIError(values.back().fullname);
848 792 }
849 793 }
850   - } catch (const FileError &) {
  794 + } catch(const FileError &) {
851 795 if(config_required_)
852 796 throw;
853 797 }
854 798 }
855 799  
856   -
857 800 // Get envname options if not yet passed
858   - for(const Option_p& opt : options_) {
859   - if (opt->count() == 0 && opt->envname_ != "") {
  801 + for(const Option_p &opt : options_) {
  802 + if(opt->count() == 0 && opt->envname_ != "") {
860 803 char *ename = std::getenv(opt->envname_.c_str());
861 804 if(ename != nullptr) {
862 805 opt->add_result(std::string(ename));
... ... @@ -865,45 +808,48 @@ protected:
865 808 }
866 809  
867 810 // Process callbacks
868   - for(const Option_p& opt : options_) {
869   - if (opt->count() > 0 && !opt->get_callback_run()) {
  811 + for(const Option_p &opt : options_) {
  812 + if(opt->count() > 0 && !opt->get_callback_run()) {
870 813 opt->run_callback();
871 814 }
872 815 }
873 816  
874   - // Verify required options
875   - for(const Option_p& opt : options_) {
  817 + // Verify required options
  818 + for(const Option_p &opt : options_) {
876 819 // Required
877   - if (opt->get_required()
878   - && (static_cast<int>( opt->count()) < opt->get_expected() || opt->count() == 0))
  820 + if(opt->get_required() && (static_cast<int>(opt->count()) < opt->get_expected() || opt->count() == 0))
879 821 throw RequiredError(opt->get_name());
880 822 // Requires
881   - for (const Option* opt_req : opt->requires_)
882   - if (opt->count() > 0 && opt_req->count() == 0)
  823 + for(const Option *opt_req : opt->requires_)
  824 + if(opt->count() > 0 && opt_req->count() == 0)
883 825 throw RequiresError(opt->get_name(), opt_req->get_name());
884 826 // Excludes
885   - for (const Option* opt_ex : opt->excludes_)
886   - if (opt->count() > 0 && opt_ex->count() != 0)
  827 + for(const Option *opt_ex : opt->excludes_)
  828 + if(opt->count() > 0 && opt_ex->count() != 0)
887 829 throw ExcludesError(opt->get_name(), opt_ex->get_name());
888 830 }
889 831  
890   - auto selected_subcommands =get_subcommands();
  832 + auto selected_subcommands = get_subcommands();
891 833 if(require_subcommand_ < 0 && selected_subcommands.empty())
892 834 throw RequiredError("Subcommand required");
893   - else if(require_subcommand_ > 0 && static_cast<int>( selected_subcommands.size()) != require_subcommand_)
  835 + else if(require_subcommand_ > 0 && static_cast<int>(selected_subcommands.size()) != require_subcommand_)
894 836 throw RequiredError(std::to_string(require_subcommand_) + " subcommand(s) required");
895 837  
896 838 // Convert missing (pairs) to extras (string only)
897 839 if(parent_ == nullptr) {
898 840 args.resize(missing()->size());
899   - std::transform(std::begin(*missing()), std::end(*missing()), std::begin(args),
900   - [](const std::pair<detail::Classifer, std::string>& val){return val.second;});
  841 + std::transform(std::begin(*missing()),
  842 + std::end(*missing()),
  843 + std::begin(args),
  844 + [](const std::pair<detail::Classifer, std::string> &val) { return val.second; });
901 845 std::reverse(std::begin(args), std::end(args));
902 846  
903   - size_t num_left_over = std::count_if(std::begin(*missing()), std::end(*missing()),
904   - [](std::pair<detail::Classifer, std::string>& val){return val.first != detail::Classifer::POSITIONAL_MARK;});
  847 + size_t num_left_over = std::count_if(
  848 + std::begin(*missing()), std::end(*missing()), [](std::pair<detail::Classifer, std::string> &val) {
  849 + return val.first != detail::Classifer::POSITIONAL_MARK;
  850 + });
905 851  
906   - if(num_left_over>0 && !allow_extras_)
  852 + if(num_left_over > 0 && !allow_extras_)
907 853 throw ExtrasError("[" + detail::rjoin(args, " ") + "]");
908 854 }
909 855 }
... ... @@ -913,29 +859,28 @@ protected:
913 859 /// If this has more than one dot.separated.name, go into the subcommand matching it
914 860 /// Returns true if it managed to find the option, if false you'll need to remove the arg manully.
915 861 bool _parse_ini(std::vector<detail::ini_ret_t> &args) {
916   - detail::ini_ret_t& current = args.back();
  862 + detail::ini_ret_t &current = args.back();
917 863 std::string parent = current.parent(); // respects curent.level
918 864 std::string name = current.name();
919 865  
920 866 // If a parent is listed, go to a subcommand
921 867 if(parent != "") {
922 868 current.level++;
923   - for(const App_p &com : subcommands_)
  869 + for(const App_p &com : subcommands_)
924 870 if(com->check_name(parent))
925 871 return com->_parse_ini(args);
926 872 return false;
927 873 }
928 874  
929   - auto op_ptr = std::find_if(std::begin(options_), std::end(options_),
930   - [name](const Option_p &v){return v->check_lname(name);});
931   -
932   - if(op_ptr == std::end(options_))
  875 + auto op_ptr = std::find_if(
  876 + std::begin(options_), std::end(options_), [name](const Option_p &v) { return v->check_lname(name); });
  877 +
  878 + if(op_ptr == std::end(options_))
933 879 return false;
934   -
  880 +
935 881 // Let's not go crazy with pointer syntax
936   - Option_p& op = *op_ptr;
  882 + Option_p &op = *op_ptr;
937 883  
938   -
939 884 if(op->results_.empty()) {
940 885 // Flag parsing
941 886 if(op->get_expected() == 0) {
... ... @@ -949,9 +894,9 @@ protected:
949 894 else
950 895 try {
951 896 size_t ui = std::stoul(val);
952   - for (size_t i=0; i<ui; i++)
  897 + for(size_t i = 0; i < ui; i++)
953 898 op->results_.emplace_back("");
954   - } catch (const std::invalid_argument &) {
  899 + } catch(const std::invalid_argument &) {
955 900 throw ConversionError(current.fullname + ": Should be true/false or a number");
956 901 }
957 902 } else
... ... @@ -966,7 +911,8 @@ protected:
966 911 return true;
967 912 }
968 913  
969   - /// Parse "one" argument (some may eat more than one), delegate to parent if fails, add to missing if missing from master
  914 + /// Parse "one" argument (some may eat more than one), delegate to parent if fails, add to missing if missing from
  915 + /// master
970 916 void _parse_single(std::vector<std::string> &args, bool &positional_only) {
971 917  
972 918 detail::Classifer classifer = positional_only ? detail::Classifer::NONE : _recognize(args.back());
... ... @@ -991,20 +937,16 @@ protected:
991 937 // Probably a positional or something for a parent (sub)command
992 938 _parse_positional(args);
993 939 }
994   -
995   -
996 940 }
997 941  
998 942 /// Parse a positional, go up the tree to check
999 943 void _parse_positional(std::vector<std::string> &args) {
1000 944  
1001 945 std::string positional = args.back();
1002   - for(const Option_p& opt : options_) {
  946 + for(const Option_p &opt : options_) {
1003 947 // Eat options, one by one, until done
1004   - if ( opt->get_positional()
1005   - && (static_cast<int>( opt->count()) < opt->get_expected()
1006   - || opt->get_expected() < 0)
1007   - ) {
  948 + if(opt->get_positional() &&
  949 + (static_cast<int>(opt->count()) < opt->get_expected() || opt->get_expected() < 0)) {
1008 950  
1009 951 opt->add_result(positional);
1010 952 args.pop_back();
... ... @@ -1025,7 +967,7 @@ protected:
1025 967 /// Unlike the others, this one will always allow fallthrough
1026 968 void _parse_subcommand(std::vector<std::string> &args) {
1027 969 for(const App_p &com : subcommands_) {
1028   - if(com->check_name(args.back())){
  970 + if(com->check_name(args.back())) {
1029 971 args.pop_back();
1030 972 com->_parse(args);
1031 973 return;
... ... @@ -1036,7 +978,7 @@ protected:
1036 978 else
1037 979 throw HorribleError("Subcommand " + args.back() + " missing");
1038 980 }
1039   -
  981 +
1040 982 /// Parse a short argument, must be at the top of the list
1041 983 void _parse_short(std::vector<std::string> &args) {
1042 984 std::string current = args.back();
... ... @@ -1046,8 +988,8 @@ protected:
1046 988 if(!detail::split_short(current, name, rest))
1047 989 throw HorribleError("Short");
1048 990  
1049   - auto op_ptr = std::find_if(std::begin(options_), std::end(options_), [name](const Option_p &opt){return opt->check_sname(name);});
1050   -
  991 + auto op_ptr = std::find_if(
  992 + std::begin(options_), std::end(options_), [name](const Option_p &opt) { return opt->check_sname(name); });
1051 993  
1052 994 // Option not found
1053 995 if(op_ptr == std::end(options_)) {
... ... @@ -1064,33 +1006,32 @@ protected:
1064 1006  
1065 1007 args.pop_back();
1066 1008  
1067   -
1068 1009 // Get a reference to the pointer to make syntax bearable
1069   - Option_p& op = *op_ptr;
  1010 + Option_p &op = *op_ptr;
1070 1011  
1071 1012 int num = op->get_expected();
1072   -
  1013 +
1073 1014 if(num == 0)
1074 1015 op->add_result("");
1075   - else if(rest!="") {
1076   - if (num > 0)
  1016 + else if(rest != "") {
  1017 + if(num > 0)
1077 1018 num--;
1078 1019 op->add_result(rest);
1079 1020 rest = "";
1080 1021 }
1081 1022  
1082   -
1083 1023 if(num == -1) {
1084 1024 while(!args.empty() && _recognize(args.back()) == detail::Classifer::NONE) {
1085 1025 op->add_result(args.back());
1086 1026 args.pop_back();
1087 1027 }
1088   - } else while(num>0 && !args.empty()) {
1089   - num--;
1090   - std::string current_ = args.back();
1091   - args.pop_back();
1092   - op->add_result(current_);
1093   - }
  1028 + } else
  1029 + while(num > 0 && !args.empty()) {
  1030 + num--;
  1031 + std::string current_ = args.back();
  1032 + args.pop_back();
  1033 + op->add_result(current_);
  1034 + }
1094 1035  
1095 1036 if(rest != "") {
1096 1037 rest = "-" + rest;
... ... @@ -1107,7 +1048,8 @@ protected:
1107 1048 if(!detail::split_long(current, name, value))
1108 1049 throw HorribleError("Long:" + args.back());
1109 1050  
1110   - auto op_ptr = std::find_if(std::begin(options_), std::end(options_), [name](const Option_p &v){return v->check_lname(name);});
  1051 + auto op_ptr = std::find_if(
  1052 + std::begin(options_), std::end(options_), [name](const Option_p &v) { return v->check_lname(name); });
1111 1053  
1112 1054 // Option not found
1113 1055 if(op_ptr == std::end(options_)) {
... ... @@ -1125,14 +1067,15 @@ protected:
1125 1067 args.pop_back();
1126 1068  
1127 1069 // Get a reference to the pointer to make syntax bearable
1128   - Option_p& op = *op_ptr;
  1070 + Option_p &op = *op_ptr;
1129 1071  
1130 1072 int num = op->get_expected();
1131   -
  1073 +
1132 1074 if(value != "") {
1133   - if(num!=-1) num--;
  1075 + if(num != -1)
  1076 + num--;
1134 1077 op->add_result(value);
1135   - } else if (num == 0) {
  1078 + } else if(num == 0) {
1136 1079 op->add_result("");
1137 1080 }
1138 1081  
... ... @@ -1141,14 +1084,14 @@ protected:
1141 1084 op->add_result(args.back());
1142 1085 args.pop_back();
1143 1086 }
1144   - } else while(num>0 && !args.empty()) {
1145   - num--;
1146   - op->add_result(args.back());
1147   - args.pop_back();
1148   - }
  1087 + } else
  1088 + while(num > 0 && !args.empty()) {
  1089 + num--;
  1090 + op->add_result(args.back());
  1091 + args.pop_back();
  1092 + }
1149 1093 return;
1150 1094 }
1151   -
1152 1095 };
1153 1096  
1154 1097 namespace detail {
... ... @@ -1156,29 +1099,26 @@ namespace detail {
1156 1099 struct AppFriend {
1157 1100  
1158 1101 /// Wrap _parse_short, perfectly forward arguments and return
1159   - template<typename ...Args>
1160   - static auto parse_short(App* app, Args && ...args)
1161   - -> typename std::result_of<decltype(&App::_parse_short)(App, Args...)>::type {
  1102 + template <typename... Args>
  1103 + static auto parse_short(App *app, Args &&... args) ->
  1104 + typename std::result_of<decltype (&App::_parse_short)(App, Args...)>::type {
1162 1105 return app->_parse_short(std::forward<Args>(args)...);
1163 1106 }
1164 1107  
1165   -
1166 1108 /// Wrap _parse_long, perfectly forward arguments and return
1167   - template<typename ...Args>
1168   - static auto parse_long(App* app, Args && ...args)
1169   - -> typename std::result_of<decltype(&App::_parse_long)(App, Args...)>::type {
  1109 + template <typename... Args>
  1110 + static auto parse_long(App *app, Args &&... args) ->
  1111 + typename std::result_of<decltype (&App::_parse_long)(App, Args...)>::type {
1170 1112 return app->_parse_long(std::forward<Args>(args)...);
1171 1113 }
1172 1114  
1173 1115 /// Wrap _parse_subcommand, perfectly forward arguments and return
1174   - template<typename ...Args>
1175   - static auto parse_subcommand(App* app, Args && ...args)
1176   - -> typename std::result_of<decltype(&App::_parse_subcommand)(App, Args...)>::type {
  1116 + template <typename... Args>
  1117 + static auto parse_subcommand(App *app, Args &&... args) ->
  1118 + typename std::result_of<decltype (&App::_parse_subcommand)(App, Args...)>::type {
1177 1119 return app->_parse_subcommand(std::forward<Args>(args)...);
1178 1120 }
1179   -
1180 1121 };
1181 1122 } // namespace detail
1182 1123  
1183 1124 } // namespace CLI
1184   -
... ...
include/CLI/CLI.hpp
... ... @@ -12,4 +12,3 @@
12 12 #include "CLI/StringTools.hpp"
13 13 #include "CLI/TypeTools.hpp"
14 14 #include "CLI/Validators.hpp"
15   -
... ...
include/CLI/Error.hpp
... ... @@ -9,10 +9,11 @@
9 9  
10 10 namespace CLI {
11 11  
12   -/// These codes are part of every error in CLI. They can be obtained from e using e.exit_code or as a quick shortcut, int values from e.get_error_code().
  12 +/// These codes are part of every error in CLI. They can be obtained from e using e.exit_code or as a quick shortcut,
  13 +/// int values from e.get_error_code().
13 14 enum class ExitCodes {
14 15 Success = 0,
15   - IncorrectConstruction=100,
  16 + IncorrectConstruction = 100,
16 17 BadNameString,
17 18 OptionAlreadyAdded,
18 19 File,
... ... @@ -41,17 +42,23 @@ enum class ExitCodes {
41 42 struct Error : public std::runtime_error {
42 43 int exit_code;
43 44 bool print_help;
44   - int get_exit_code() const {return exit_code;}
45   - Error(std::string parent, std::string name, ExitCodes exit_code=ExitCodes::BaseClass, bool print_help=true)
  45 + int get_exit_code() const { return exit_code; }
  46 + Error(std::string parent, std::string name, ExitCodes exit_code = ExitCodes::BaseClass, bool print_help = true)
46 47 : runtime_error(parent + ": " + name), exit_code(static_cast<int>(exit_code)), print_help(print_help) {}
47   - Error(std::string parent, std::string name, int exit_code=static_cast<int>(ExitCodes::BaseClass), bool print_help=true)
  48 + Error(std::string parent,
  49 + std::string name,
  50 + int exit_code = static_cast<int>(ExitCodes::BaseClass),
  51 + bool print_help = true)
48 52 : runtime_error(parent + ": " + name), exit_code(exit_code), print_help(print_help) {}
49 53 };
50 54  
51 55 /// Construction errors (not in parsing)
52 56 struct ConstructionError : public Error {
53 57 // Using Error::Error constructors seem to not work on GCC 4.7
54   - ConstructionError(std::string parent, std::string name, ExitCodes exit_code=ExitCodes::BaseClass, bool print_help=true)
  58 + ConstructionError(std::string parent,
  59 + std::string name,
  60 + ExitCodes exit_code = ExitCodes::BaseClass,
  61 + bool print_help = true)
55 62 : Error(parent, name, exit_code, print_help) {}
56 63 };
57 64  
... ... @@ -63,8 +70,7 @@ struct IncorrectConstruction : public ConstructionError {
63 70  
64 71 /// Thrown on construction of a bad name
65 72 struct BadNameString : public ConstructionError {
66   - BadNameString(std::string name)
67   - : ConstructionError("BadNameString", name, ExitCodes::BadNameString) {}
  73 + BadNameString(std::string name) : ConstructionError("BadNameString", name, ExitCodes::BadNameString) {}
68 74 };
69 75  
70 76 /// Thrown when an option already exists
... ... @@ -77,7 +83,7 @@ struct OptionAlreadyAdded : public ConstructionError {
77 83  
78 84 /// Anything that can error in Parse
79 85 struct ParseError : public Error {
80   - ParseError(std::string parent, std::string name, ExitCodes exit_code=ExitCodes::BaseClass, bool print_help=true)
  86 + ParseError(std::string parent, std::string name, ExitCodes exit_code = ExitCodes::BaseClass, bool print_help = true)
81 87 : Error(parent, name, exit_code, print_help) {}
82 88 };
83 89  
... ... @@ -85,8 +91,7 @@ struct ParseError : public Error {
85 91  
86 92 /// This is a successful completion on parsing, supposed to exit
87 93 struct Success : public ParseError {
88   - Success()
89   - : ParseError("Success", "Successfully completed, should be caught and quit", ExitCodes::Success, false) {}
  94 + Success() : ParseError("Success", "Successfully completed, should be caught and quit", ExitCodes::Success, false) {}
90 95 };
91 96  
92 97 /// -h or --help on command line
... ... @@ -95,29 +100,24 @@ struct CallForHelp : public ParseError {
95 100 : ParseError("CallForHelp", "This should be caught in your main function, see examples", ExitCodes::Success) {}
96 101 };
97 102  
98   -
99 103 /// Thrown when parsing an INI file and it is missing
100 104 struct FileError : public ParseError {
101   - FileError (std::string name)
102   - : ParseError("FileError", name, ExitCodes::File) {}
  105 + FileError(std::string name) : ParseError("FileError", name, ExitCodes::File) {}
103 106 };
104 107  
105 108 /// Thrown when conversion call back fails, such as when an int fails to coerse to a string
106 109 struct ConversionError : public ParseError {
107   - ConversionError(std::string name)
108   - : ParseError("ConversionError", name, ExitCodes::Conversion) {}
  110 + ConversionError(std::string name) : ParseError("ConversionError", name, ExitCodes::Conversion) {}
109 111 };
110 112  
111 113 /// Thrown when validation of results fails
112 114 struct ValidationError : public ParseError {
113   - ValidationError(std::string name)
114   - : ParseError("ValidationError", name, ExitCodes::Validation) {}
  115 + ValidationError(std::string name) : ParseError("ValidationError", name, ExitCodes::Validation) {}
115 116 };
116 117  
117 118 /// Thrown when a required option is missing
118 119 struct RequiredError : public ParseError {
119   - RequiredError(std::string name)
120   - : ParseError("RequiredError", name, ExitCodes::Required) {}
  120 + RequiredError(std::string name) : ParseError("RequiredError", name, ExitCodes::Required) {}
121 121 };
122 122  
123 123 /// Thrown when a requires option is missing
... ... @@ -134,20 +134,17 @@ struct ExcludesError : public ParseError {
134 134  
135 135 /// Thrown when too many positionals or options are found
136 136 struct ExtrasError : public ParseError {
137   - ExtrasError(std::string name)
138   - : ParseError("ExtrasError", name, ExitCodes::Extras) {}
  137 + ExtrasError(std::string name) : ParseError("ExtrasError", name, ExitCodes::Extras) {}
139 138 };
140 139  
141 140 /// Thrown when extra values are found in an INI file
142 141 struct ExtrasINIError : public ParseError {
143   - ExtrasINIError(std::string name)
144   - : ParseError("ExtrasINIError", name, ExitCodes::ExtrasINI) {}
  142 + ExtrasINIError(std::string name) : ParseError("ExtrasINIError", name, ExitCodes::ExtrasINI) {}
145 143 };
146 144  
147 145 /// Thrown when validation fails before parsing
148 146 struct InvalidError : public ParseError {
149   - InvalidError(std::string name)
150   - : ParseError("InvalidError", name, ExitCodes::Invalid) {}
  147 + InvalidError(std::string name) : ParseError("InvalidError", name, ExitCodes::Invalid) {}
151 148 };
152 149  
153 150 /// This is just a safety check to verify selection and parsing match
... ... @@ -160,8 +157,7 @@ struct HorribleError : public ParseError {
160 157  
161 158 /// Thrown when counting a non-existent option
162 159 struct OptionNotFound : public Error {
163   - OptionNotFound(std::string name)
164   - : Error("OptionNotFound", name, ExitCodes::OptionNotFound) {}
  160 + OptionNotFound(std::string name) : Error("OptionNotFound", name, ExitCodes::OptionNotFound) {}
165 161 };
166 162  
167 163 /// @}
... ...
include/CLI/Ini.hpp
... ... @@ -10,18 +10,17 @@
10 10  
11 11 #include "CLI/StringTools.hpp"
12 12  
13   -
14 13 namespace CLI {
15 14 namespace detail {
16 15  
17 16 inline std::string inijoin(std::vector<std::string> args) {
18 17 std::ostringstream s;
19 18 size_t start = 0;
20   - for (const auto& arg : args) {
  19 + for(const auto &arg : args) {
21 20 if(start++ > 0)
22 21 s << " ";
23 22  
24   - auto it = std::find_if(arg.begin(), arg.end(), [](char ch){ return std::isspace<char>(ch , std::locale());});
  23 + auto it = std::find_if(arg.begin(), arg.end(), [](char ch) { return std::isspace<char>(ch, std::locale()); });
25 24 if(it == arg.end())
26 25 s << arg;
27 26 else if(arg.find(R"(")") == std::string::npos)
... ... @@ -47,18 +46,18 @@ struct ini_ret_t {
47 46 ///
48 47 /// Level 0, a.b.c would return a
49 48 /// Level 1, a.b.c could return b
50   - std::string parent () const {
  49 + std::string parent() const {
51 50 std::vector<std::string> plist = detail::split(fullname, '.');
52   - if(plist.size() > (level+1))
  51 + if(plist.size() > (level + 1))
53 52 return plist[level];
54 53 else
55 54 return "";
56 55 }
57 56  
58 57 /// Return name
59   - std::string name () const {
  58 + std::string name() const {
60 59 std::vector<std::string> plist = detail::split(fullname, '.');
61   - return plist.at(plist.size()-1);
  60 + return plist.at(plist.size() - 1);
62 61 }
63 62 };
64 63  
... ... @@ -74,17 +73,17 @@ inline std::vector&lt;ini_ret_t&gt; parse_ini(std::istream &amp;input) {
74 73  
75 74 detail::trim(line);
76 75 size_t len = line.length();
77   - if(len > 1 && line[0] == '[' && line[len-1] == ']') {
78   - section = line.substr(1,len-2);
79   - } else if (len > 0 && line[0] != ';') {
  76 + if(len > 1 && line[0] == '[' && line[len - 1] == ']') {
  77 + section = line.substr(1, len - 2);
  78 + } else if(len > 0 && line[0] != ';') {
80 79 output.emplace_back();
81   - ini_ret_t& out = output.back();
  80 + ini_ret_t &out = output.back();
82 81  
83 82 // Find = in string, split and recombine
84 83 auto pos = line.find("=");
85 84 if(pos != std::string::npos) {
86   - name = detail::trim_copy(line.substr(0,pos));
87   - std::string item = detail::trim_copy(line.substr(pos+1));
  85 + name = detail::trim_copy(line.substr(0, pos));
  86 + std::string item = detail::trim_copy(line.substr(pos + 1));
88 87 items = detail::split_up(item);
89 88 } else {
90 89 name = detail::trim_copy(line);
... ... @@ -112,6 +111,5 @@ inline std::vector&lt;ini_ret_t&gt; parse_ini(const std::string &amp;name) {
112 111 return parse_ini(input);
113 112 }
114 113  
115   -
116 114 } // namespace detail
117 115 } // namespace CLI
... ...
include/CLI/Option.hpp
... ... @@ -19,17 +19,17 @@
19 19 namespace CLI {
20 20  
21 21 using results_t = std::vector<std::string>;
22   -using callback_t = std::function<bool (results_t)>;
  22 +using callback_t = std::function<bool(results_t)>;
23 23  
24 24 class Option;
25 25 class App;
26 26  
27 27 using Option_p = std::unique_ptr<Option>;
28 28  
29   -
30 29 class Option {
31 30 friend App;
32   -protected:
  31 +
  32 + protected:
33 33 /// @name Names
34 34 ///@{
35 35  
... ... @@ -48,7 +48,7 @@ protected:
48 48 ///@}
49 49 /// @name Help
50 50 ///@{
51   -
  51 +
52 52 /// The description for help strings
53 53 std::string description_;
54 54  
... ... @@ -59,47 +59,46 @@ protected:
59 59 std::string typeval_;
60 60  
61 61 /// The group membership
62   - std::string group_ {"Options"};
  62 + std::string group_{"Options"};
63 63  
64 64 /// True if this option has a default
65   - bool default_ {false};
  65 + bool default_{false};
66 66  
67 67 ///@}
68 68 /// @name Configuration
69 69 ///@{
70   -
  70 +
71 71 /// True if this is a required option
72   - bool required_ {false};
  72 + bool required_{false};
73 73  
74 74 /// The number of expected values, 0 for flag, -1 for unlimited vector
75   - int expected_ {1};
  75 + int expected_{1};
76 76  
77 77 /// A private setting to allow args to not be able to accept incorrect expected values
78   - bool changeable_ {false};
79   -
  78 + bool changeable_{false};
  79 +
80 80 /// Ignore the case when matching (option, not value)
81   - bool ignore_case_ {false};
  81 + bool ignore_case_{false};
82 82  
83 83 /// A list of validators to run on each value parsed
84 84 std::vector<std::function<bool(std::string)>> validators_;
85 85  
86 86 /// A list of options that are required with this option
87   - std::set<Option*> requires_;
  87 + std::set<Option *> requires_;
88 88  
89 89 /// A list of options that are excluded with this option
90   - std::set<Option*> excludes_;
  90 + std::set<Option *> excludes_;
91 91  
92 92 ///@}
93 93 /// @name Other
94 94 ///@{
95 95  
96 96 /// Remember the parent app
97   - App* parent_;
  97 + App *parent_;
98 98  
99 99 /// Options store a callback to do all the work
100 100 callback_t callback_;
101 101  
102   -
103 102 ///@}
104 103 /// @name Parsing results
105 104 ///@{
... ... @@ -108,54 +107,48 @@ protected:
108 107 results_t results_;
109 108  
110 109 /// Whether the callback has run (needed for INI parsing)
111   - bool callback_run_ {false};
  110 + bool callback_run_{false};
112 111  
113 112 ///@}
114 113  
115 114 /// Making an option by hand is not defined, it must be made by the App class
116   - Option(std::string name, std::string description = "", std::function<bool(results_t)> callback=[](results_t){return true;}, bool default_=true, App* parent = nullptr) :
117   - description_(std::move(description)), default_(default_), parent_(parent), callback_(std::move(callback)) {
  115 + Option(std::string name,
  116 + std::string description = "",
  117 + std::function<bool(results_t)> callback = [](results_t) { return true; },
  118 + bool default_ = true,
  119 + App *parent = nullptr)
  120 + : description_(std::move(description)), default_(default_), parent_(parent), callback_(std::move(callback)) {
118 121 std::tie(snames_, lnames_, pname_) = detail::get_names(detail::split_names(name));
119 122 }
120 123  
121   -public:
122   -
  124 + public:
123 125 /// @name Basic
124 126 ///@{
125 127  
126 128 /// Count the total number of times an option was passed
127   - size_t count() const {
128   - return results_.size();
129   - }
  129 + size_t count() const { return results_.size(); }
130 130  
131   -
132 131 /// This class is true if option is passed.
133   - operator bool() const {
134   - return count() > 0;
135   - }
  132 + operator bool() const { return count() > 0; }
136 133  
137 134 /// Clear the parsed results (mostly for testing)
138   - void clear() {
139   - results_.clear();
140   - }
  135 + void clear() { results_.clear(); }
141 136  
142 137 ///@}
143 138 /// @name Setting options
144 139 ///@{
145 140  
146 141 /// Set the option as required
147   - Option* required(bool value = true) {
  142 + Option *required(bool value = true) {
148 143 required_ = value;
149 144 return this;
150 145 }
151 146  
152 147 /// Support Plubmum term
153   - Option* mandatory(bool value = true) {
154   - return required(value);
155   - }
  148 + Option *mandatory(bool value = true) { return required(value); }
156 149  
157 150 /// Set the number of expected arguments (Flags bypass this)
158   - Option* expected(int value) {
  151 + Option *expected(int value) {
159 152 if(value == 0)
160 153 throw IncorrectConstruction("Cannot set 0 expected, use a flag instead");
161 154 else if(expected_ == 0)
... ... @@ -167,21 +160,20 @@ public:
167 160 }
168 161  
169 162 /// Adds a validator
170   - Option* check(std::function<bool(std::string)> validator) {
  163 + Option *check(std::function<bool(std::string)> validator) {
171 164  
172 165 validators_.push_back(validator);
173 166 return this;
174 167 }
175 168  
176 169 /// Changes the group membership
177   - Option* group(std::string name) {
  170 + Option *group(std::string name) {
178 171 group_ = name;
179 172 return this;
180 173 }
181 174  
182   -
183 175 /// Sets required options
184   - Option* requires(Option* opt) {
  176 + Option *requires(Option *opt) {
185 177 auto tup = requires_.insert(opt);
186 178 if(!tup.second)
187 179 throw OptionAlreadyAdded(get_name() + " requires " + opt->get_name());
... ... @@ -189,24 +181,21 @@ public:
189 181 }
190 182  
191 183 /// Can find a string if needed
192   - template<typename T=App>
193   - Option* requires(std::string opt_name) {
194   - for(const Option_p& opt : dynamic_cast<T*>(parent_)->options_)
  184 + template <typename T = App> Option *requires(std::string opt_name) {
  185 + for(const Option_p &opt : dynamic_cast<T *>(parent_)->options_)
195 186 if(opt.get() != this && opt->check_name(opt_name))
196 187 return requires(opt.get());
197 188 throw IncorrectConstruction("Option " + opt_name + " is not defined");
198   -
199 189 }
200 190  
201 191 /// Any number supported, any mix of string and Opt
202   - template<typename A, typename B, typename... ARG>
203   - Option* requires(A opt, B opt1, ARG... args) {
  192 + template <typename A, typename B, typename... ARG> Option *requires(A opt, B opt1, ARG... args) {
204 193 requires(opt);
205 194 return requires(opt1, args...);
206 195 }
207 196  
208 197 /// Sets excluded options
209   - Option* excludes(Option* opt) {
  198 + Option *excludes(Option *opt) {
210 199 auto tup = excludes_.insert(opt);
211 200 if(!tup.second)
212 201 throw OptionAlreadyAdded(get_name() + " excludes " + opt->get_name());
... ... @@ -214,23 +203,20 @@ public:
214 203 }
215 204  
216 205 /// Can find a string if needed
217   - template<typename T=App>
218   - Option* excludes(std::string opt_name) {
219   - for(const Option_p& opt : dynamic_cast<T*>(parent_)->options_)
  206 + template <typename T = App> Option *excludes(std::string opt_name) {
  207 + for(const Option_p &opt : dynamic_cast<T *>(parent_)->options_)
220 208 if(opt.get() != this && opt->check_name(opt_name))
221 209 return excludes(opt.get());
222 210 throw IncorrectConstruction("Option " + opt_name + " is not defined");
223   -
224 211 }
225 212 /// Any number supported, any mix of string and Opt
226   - template<typename A, typename B, typename... ARG>
227   - Option* excludes(A opt, B opt1, ARG... args) {
  213 + template <typename A, typename B, typename... ARG> Option *excludes(A opt, B opt1, ARG... args) {
228 214 excludes(opt);
229 215 return excludes(opt1, args...);
230 216 }
231 217  
232 218 /// Sets environment variable to read if no option given
233   - Option* envname(std::string name) {
  219 + Option *envname(std::string name) {
234 220 envname_ = name;
235 221 return this;
236 222 }
... ... @@ -239,10 +225,9 @@ public:
239 225 ///
240 226 /// The template hides the fact that we don't have the definition of App yet.
241 227 /// You are never expected to add an argument to the template here.
242   - template<typename T=App>
243   - Option* ignore_case(bool value = true) {
  228 + template <typename T = App> Option *ignore_case(bool value = true) {
244 229 ignore_case_ = value;
245   - for(const Option_p& opt : dynamic_cast<T*>(parent_)->options_)
  230 + for(const Option_p &opt : dynamic_cast<T *>(parent_)->options_)
246 231 if(opt.get() != this && *opt == *this)
247 232 throw OptionAlreadyAdded(opt->get_name());
248 233 return this;
... ... @@ -251,76 +236,58 @@ public:
251 236 ///@}
252 237 /// @name Accessors
253 238 ///@{
254   -
  239 +
255 240 /// True if this is a required option
256   - bool get_required() const {
257   - return required_;
258   - }
  241 + bool get_required() const { return required_; }
259 242  
260 243 /// The number of arguments the option expects
261   - int get_expected() const {
262   - return expected_;
263   - }
  244 + int get_expected() const { return expected_; }
264 245  
265 246 /// True if this has a default value
266   - int get_default() const {
267   - return default_;
268   - }
  247 + int get_default() const { return default_; }
269 248  
270 249 /// True if the argument can be given directly
271   - bool get_positional() const {
272   - return pname_.length() > 0;
273   - }
  250 + bool get_positional() const { return pname_.length() > 0; }
274 251  
275 252 /// True if option has at least one non-positional name
276   - bool nonpositional() const {
277   - return (snames_.size() + lnames_.size()) > 0;
278   - }
  253 + bool nonpositional() const { return (snames_.size() + lnames_.size()) > 0; }
279 254  
280 255 /// True if option has description
281   - bool has_description() const {
282   - return description_.length() > 0;
283   - }
  256 + bool has_description() const { return description_.length() > 0; }
284 257  
285 258 /// Get the group of this option
286   - const std::string& get_group() const {
287   - return group_;
288   - }
  259 + const std::string &get_group() const { return group_; }
289 260  
290 261 /// Get the description
291   - const std::string& get_description() const {
292   - return description_;
293   - }
  262 + const std::string &get_description() const { return description_; }
294 263  
295 264 // Just the pname
296   - std::string get_pname() const {
297   - return pname_;
298   - }
299   -
  265 + std::string get_pname() const { return pname_; }
  266 +
300 267 ///@}
301 268 /// @name Help tools
302 269 ///@{
303 270  
304 271 /// Gets a , sep list of names. Does not include the positional name if opt_only=true.
305   - std::string get_name(bool opt_only=false) const {
  272 + std::string get_name(bool opt_only = false) const {
306 273 std::vector<std::string> name_list;
307 274 if(!opt_only && pname_.length() > 0)
308 275 name_list.push_back(pname_);
309   - for(const std::string& sname : snames_)
310   - name_list.push_back("-"+sname);
311   - for(const std::string& lname : lnames_)
312   - name_list.push_back("--"+lname);
  276 + for(const std::string &sname : snames_)
  277 + name_list.push_back("-" + sname);
  278 + for(const std::string &lname : lnames_)
  279 + name_list.push_back("--" + lname);
313 280 return detail::join(name_list);
314 281 }
315 282  
316 283 /// The name and any extras needed for positionals
317 284 std::string help_positional() const {
318 285 std::string out = pname_;
319   - if(get_expected()>1)
  286 + if(get_expected() > 1)
320 287 out = out + "(" + std::to_string(get_expected()) + "x)";
321   - else if(get_expected()==-1)
  288 + else if(get_expected() == -1)
322 289 out = out + "...";
323   - out = get_required() ? out : "["+out+"]";
  290 + out = get_required() ? out : "[" + out + "]";
324 291 return out;
325 292 }
326 293  
... ... @@ -330,7 +297,7 @@ public:
330 297 out << get_name(true) << help_aftername();
331 298 return out.str();
332 299 }
333   -
  300 +
334 301 /// pname with type info
335 302 std::string help_pname() const {
336 303 std::stringstream out;
... ... @@ -346,7 +313,7 @@ public:
346 313 if(typeval_ != "")
347 314 out << " " << typeval_;
348 315 if(defaultval_ != "")
349   - out << "=" << defaultval_;
  316 + out << "=" << defaultval_;
350 317 if(get_expected() > 1)
351 318 out << " x " << get_expected();
352 319 if(get_expected() == -1)
... ... @@ -356,29 +323,27 @@ public:
356 323 out << " (env:" << envname_ << ")";
357 324 if(!requires_.empty()) {
358 325 out << " Requires:";
359   - for(const Option* opt : requires_)
  326 + for(const Option *opt : requires_)
360 327 out << " " << opt->get_name();
361 328 }
362 329 if(!excludes_.empty()) {
363 330 out << " Excludes:";
364   - for(const Option* opt : excludes_)
  331 + for(const Option *opt : excludes_)
365 332 out << " " << opt->get_name();
366 333 }
367 334 return out.str();
368   -
369 335 }
370 336  
371   -
372 337 ///@}
373 338 /// @name Parser tools
374 339 ///@{
375   -
  340 +
376 341 /// Process the callback
377 342 void run_callback() const {
378 343 if(!callback_(results_))
379 344 throw ConversionError(get_name() + "=" + detail::join(results_));
380 345 if(!validators_.empty()) {
381   - for(const std::string & result : results_)
  346 + for(const std::string &result : results_)
382 347 for(const std::function<bool(std::string)> &vali : validators_)
383 348 if(!vali(result))
384 349 throw ValidationError(get_name() + "=" + result);
... ... @@ -386,7 +351,7 @@ public:
386 351 }
387 352  
388 353 /// If options share any of the same names, they are equal (not counting positional)
389   - bool operator== (const Option& other) const {
  354 + bool operator==(const Option &other) const {
390 355 for(const std::string &sname : snames_)
391 356 if(other.check_sname(sname))
392 357 return true;
... ... @@ -406,9 +371,9 @@ public:
406 371 /// Check a name. Requires "-" or "--" for short / long, supports positional name
407 372 bool check_name(std::string name) const {
408 373  
409   - if(name.length()>2 && name.substr(0,2) == "--")
  374 + if(name.length() > 2 && name.substr(0, 2) == "--")
410 375 return check_lname(name.substr(2));
411   - else if (name.length()>1 && name.substr(0,1) == "-")
  376 + else if(name.length() > 1 && name.substr(0, 1) == "-")
412 377 return check_sname(name.substr(1));
413 378 else {
414 379 std::string local_pname = pname_;
... ... @@ -424,73 +389,60 @@ public:
424 389 bool check_sname(std::string name) const {
425 390 if(ignore_case_) {
426 391 name = detail::to_lower(name);
427   - return std::find_if(std::begin(snames_), std::end(snames_),
428   - [&name](std::string local_sname){return detail::to_lower(local_sname) == name;})
429   - != std::end(snames_);
  392 + return std::find_if(std::begin(snames_), std::end(snames_), [&name](std::string local_sname) {
  393 + return detail::to_lower(local_sname) == name;
  394 + }) != std::end(snames_);
430 395 } else
431 396 return std::find(std::begin(snames_), std::end(snames_), name) != std::end(snames_);
432 397 }
433 398  
434 399 /// Requires "--" to be removed from string
435 400 bool check_lname(std::string name) const {
436   - if(ignore_case_) {
437   - name = detail::to_lower(name);
438   - return std::find_if(std::begin(lnames_), std::end(lnames_),
439   - [&name](std::string local_sname){return detail::to_lower(local_sname) == name;})
440   - != std::end(lnames_);
  401 + if(ignore_case_) {
  402 + name = detail::to_lower(name);
  403 + return std::find_if(std::begin(lnames_), std::end(lnames_), [&name](std::string local_sname) {
  404 + return detail::to_lower(local_sname) == name;
  405 + }) != std::end(lnames_);
441 406 } else
442 407 return std::find(std::begin(lnames_), std::end(lnames_), name) != std::end(lnames_);
443 408 }
444 409  
445   -
446 410 /// Puts a result at position r
447 411 void add_result(std::string s) {
448 412 results_.push_back(s);
449 413 callback_run_ = false;
450 414 }
451 415  
452   -
453 416 /// Get a copy of the results
454   - std::vector<std::string> results() const {
455   - return results_;
456   - }
  417 + std::vector<std::string> results() const { return results_; }
457 418  
458 419 /// See if the callback has been run already
459   - bool get_callback_run() const {
460   - return callback_run_;
461   - }
  420 + bool get_callback_run() const { return callback_run_; }
462 421  
463 422 ///@}
464 423 /// @name Custom options
465 424 ///@{
466 425  
467 426 /// Set a custom option, typestring, expected, and changeable
468   - void set_custom_option(std::string typeval, int expected=1, bool changeable = false) {
  427 + void set_custom_option(std::string typeval, int expected = 1, bool changeable = false) {
469 428 typeval_ = typeval;
470 429 expected_ = expected;
471 430 changeable_ = changeable;
472 431 }
473 432  
474 433 /// Set the default value string representation
475   - void set_default_val(std::string val) {
476   - defaultval_ = val;
477   - }
  434 + void set_default_val(std::string val) { defaultval_ = val; }
478 435  
479 436 ///@}
480 437  
481   -
482   - protected:
483   -
484   -
  438 + protected:
485 439 /// @name App Helpers
486 440 ///@{
487 441 /// Can print positional name detailed option if true
488 442 bool _has_help_positional() const {
489   - return get_positional() && (has_description() || !requires_.empty() || !excludes_.empty() );
  443 + return get_positional() && (has_description() || !requires_.empty() || !excludes_.empty());
490 444 }
491 445 ///@}
492 446 };
493 447  
494   -
495   -
496 448 } // namespace CLI
... ...
include/CLI/Split.hpp
... ... @@ -15,8 +15,8 @@ namespace detail {
15 15  
16 16 // Returns false if not a short option. Otherwise, sets opt name and rest and returns true
17 17 inline bool split_short(const std::string &current, std::string &name, std::string &rest) {
18   - if(current.size()>1 && current[0] == '-' && valid_first_char(current[1])) {
19   - name = current.substr(1,1);
  18 + if(current.size() > 1 && current[0] == '-' && valid_first_char(current[1])) {
  19 + name = current.substr(1, 1);
20 20 rest = current.substr(2);
21 21 return true;
22 22 } else
... ... @@ -25,11 +25,11 @@ inline bool split_short(const std::string &amp;current, std::string &amp;name, std::stri
25 25  
26 26 // Returns false if not a long option. Otherwise, sets opt name and other side of = and returns true
27 27 inline bool split_long(const std::string &current, std::string &name, std::string &value) {
28   - if(current.size()>2 && current.substr(0,2) == "--" && valid_first_char(current[2])) {
  28 + if(current.size() > 2 && current.substr(0, 2) == "--" && valid_first_char(current[2])) {
29 29 auto loc = current.find("=");
30 30 if(loc != std::string::npos) {
31   - name = current.substr(2,loc-2);
32   - value = current.substr(loc+1);
  31 + name = current.substr(2, loc - 2);
  32 + value = current.substr(loc + 1);
33 33 } else {
34 34 name = current.substr(2);
35 35 value = "";
... ... @@ -44,18 +44,17 @@ inline std::vector&lt;std::string&gt; split_names(std::string current) {
44 44 std::vector<std::string> output;
45 45 size_t val;
46 46 while((val = current.find(",")) != std::string::npos) {
47   - output.push_back(current.substr(0,val));
48   - current = current.substr(val+1);
  47 + output.push_back(current.substr(0, val));
  48 + current = current.substr(val + 1);
49 49 }
50 50 output.push_back(current);
51 51 return output;
52   -
53 52 }
54 53  
55 54 /// Get a vector of short names, one of long names, and a single name
56   -inline std::tuple<std::vector<std::string>,std::vector<std::string>, std::string>
57   - get_names(const std::vector<std::string> &input) {
58   -
  55 +inline std::tuple<std::vector<std::string>, std::vector<std::string>, std::string>
  56 +get_names(const std::vector<std::string> &input) {
  57 +
59 58 std::vector<std::string> short_names;
60 59 std::vector<std::string> long_names;
61 60 std::string pos_name;
... ... @@ -64,30 +63,28 @@ inline std::tuple&lt;std::vector&lt;std::string&gt;,std::vector&lt;std::string&gt;, std::string
64 63 if(name.length() == 0)
65 64 continue;
66 65 else if(name.length() > 1 && name[0] == '-' && name[1] != '-') {
67   - if(name.length()==2 && valid_first_char(name[1]))
68   - short_names.emplace_back(1,name[1]);
  66 + if(name.length() == 2 && valid_first_char(name[1]))
  67 + short_names.emplace_back(1, name[1]);
69 68 else
70   - throw BadNameString("Invalid one char name: "+name);
71   - } else if(name.length() > 2 && name.substr(0,2) == "--") {
  69 + throw BadNameString("Invalid one char name: " + name);
  70 + } else if(name.length() > 2 && name.substr(0, 2) == "--") {
72 71 name = name.substr(2);
73 72 if(valid_name_string(name))
74 73 long_names.push_back(name);
75 74 else
76   - throw BadNameString("Bad long name: "+name);
  75 + throw BadNameString("Bad long name: " + name);
77 76 } else if(name == "-" || name == "--") {
78 77 throw BadNameString("Must have a name, not just dashes");
79 78 } else {
80 79 if(pos_name.length() > 0)
81   - throw BadNameString("Only one positional name allowed, remove: "+name);
  80 + throw BadNameString("Only one positional name allowed, remove: " + name);
82 81 pos_name = name;
83   -
84 82 }
85 83 }
86   -
87   - return std::tuple<std::vector<std::string>,std::vector<std::string>, std::string>
88   - (short_names, long_names, pos_name);
89   -}
90 84  
  85 + return std::tuple<std::vector<std::string>, std::vector<std::string>, std::string>(
  86 + short_names, long_names, pos_name);
  87 +}
91 88  
92 89 } // namespace detail
93 90 } // namespace CLI
... ...
include/CLI/StringTools.hpp
... ... @@ -13,32 +13,29 @@
13 13 namespace CLI {
14 14 namespace detail {
15 15  
16   -
17 16 // Based on http://stackoverflow.com/questions/236129/split-a-string-in-c
18   -///Split a string by a delim
  17 +/// Split a string by a delim
19 18 inline std::vector<std::string> split(const std::string &s, char delim) {
20 19 std::vector<std::string> elems;
21 20 // Check to see if emtpy string, give consistent result
22   - if(s=="")
  21 + if(s == "")
23 22 elems.emplace_back("");
24 23 else {
25 24 std::stringstream ss;
26 25 ss.str(s);
27 26 std::string item;
28   - while (std::getline(ss, item, delim)) {
  27 + while(std::getline(ss, item, delim)) {
29 28 elems.push_back(item);
30 29 }
31 30 }
32 31 return elems;
33 32 }
34 33  
35   -
36 34 /// Simple function to join a string
37   -template <typename T>
38   -std::string join(const T& v, std::string delim = ",") {
  35 +template <typename T> std::string join(const T &v, std::string delim = ",") {
39 36 std::ostringstream s;
40 37 size_t start = 0;
41   - for (const auto& i : v) {
  38 + for(const auto &i : v) {
42 39 if(start++ > 0)
43 40 s << delim;
44 41 s << i;
... ... @@ -47,10 +44,9 @@ std::string join(const T&amp; v, std::string delim = &quot;,&quot;) {
47 44 }
48 45  
49 46 /// Join a string in reverse order
50   -template<typename T>
51   -std::string rjoin(const T& v, std::string delim = ",") {
  47 +template <typename T> std::string rjoin(const T &v, std::string delim = ",") {
52 48 std::ostringstream s;
53   - for(size_t start=0; start<v.size(); start++) {
  49 + for(size_t start = 0; start < v.size(); start++) {
54 50 if(start > 0)
55 51 s << delim;
56 52 s << v[v.size() - start - 1];
... ... @@ -61,43 +57,39 @@ std::string rjoin(const T&amp; v, std::string delim = &quot;,&quot;) {
61 57 // Based roughly on http://stackoverflow.com/questions/25829143/c-trim-whitespace-from-a-string
62 58  
63 59 /// Trim whitespace from left of string
64   -inline std::string& ltrim(std::string &str) {
65   - auto it = std::find_if(str.begin(), str.end(), [](char ch){ return !std::isspace<char>(ch , std::locale());});
  60 +inline std::string &ltrim(std::string &str) {
  61 + auto it = std::find_if(str.begin(), str.end(), [](char ch) { return !std::isspace<char>(ch, std::locale()); });
66 62 str.erase(str.begin(), it);
67   - return str;
  63 + return str;
68 64 }
69 65  
70 66 /// Trim anything from left of string
71   -inline std::string& ltrim(std::string &str, const std::string &filter) {
72   - auto it = std::find_if(str.begin(), str.end(), [&filter](char ch){return filter.find(ch) == std::string::npos;});
  67 +inline std::string &ltrim(std::string &str, const std::string &filter) {
  68 + auto it = std::find_if(str.begin(), str.end(), [&filter](char ch) { return filter.find(ch) == std::string::npos; });
73 69 str.erase(str.begin(), it);
74 70 return str;
75 71 }
76 72  
77   -
78 73 /// Trim whitespace from right of string
79   -inline std::string& rtrim(std::string &str) {
80   - auto it = std::find_if(str.rbegin(), str.rend(), [](char ch){ return !std::isspace<char>(ch, std::locale());});
81   - str.erase(it.base() , str.end() );
82   - return str;
  74 +inline std::string &rtrim(std::string &str) {
  75 + auto it = std::find_if(str.rbegin(), str.rend(), [](char ch) { return !std::isspace<char>(ch, std::locale()); });
  76 + str.erase(it.base(), str.end());
  77 + return str;
83 78 }
84 79  
85 80 /// Trim anything from right of string
86   -inline std::string& rtrim(std::string &str, const std::string &filter) {
87   - auto it = std::find_if(str.rbegin(), str.rend(), [&filter](char ch){return filter.find(ch) == std::string::npos;});
  81 +inline std::string &rtrim(std::string &str, const std::string &filter) {
  82 + auto it =
  83 + std::find_if(str.rbegin(), str.rend(), [&filter](char ch) { return filter.find(ch) == std::string::npos; });
88 84 str.erase(it.base(), str.end());
89   - return str;
  85 + return str;
90 86 }
91 87  
92 88 /// Trim whitespace from string
93   -inline std::string& trim(std::string &str) {
94   - return ltrim(rtrim(str));
95   -}
  89 +inline std::string &trim(std::string &str) { return ltrim(rtrim(str)); }
96 90  
97 91 /// Trim anything from string
98   -inline std::string& trim(std::string &str, const std::string filter) {
99   - return ltrim(rtrim(str, filter), filter);
100   -}
  92 +inline std::string &trim(std::string &str, const std::string filter) { return ltrim(rtrim(str, filter), filter); }
101 93  
102 94 /// Make a copy of the string and then trim it
103 95 inline std::string trim_copy(const std::string &str) {
... ... @@ -113,25 +105,21 @@ inline std::string trim_copy(const std::string &amp;str, const std::string &amp;filter)
113 105 /// Print a two part "help" string
114 106 inline void format_help(std::stringstream &out, std::string name, std::string description, size_t wid) {
115 107 name = " " + name;
116   - out << std::setw(static_cast<int>( wid)) << std::left << name;
  108 + out << std::setw(static_cast<int>(wid)) << std::left << name;
117 109 if(description != "") {
118   - if(name.length()>=wid)
119   - out << std::endl << std::setw(static_cast<int>( wid)) << "";
  110 + if(name.length() >= wid)
  111 + out << std::endl << std::setw(static_cast<int>(wid)) << "";
120 112 out << description;
121 113 }
122 114 out << std::endl;
123 115 }
124 116  
125 117 /// Verify the first character of an option
126   -template<typename T>
127   -bool valid_first_char(T c) {
128   - return std::isalpha(c, std::locale()) || c=='_';
129   -}
  118 +template <typename T> bool valid_first_char(T c) { return std::isalpha(c, std::locale()) || c == '_'; }
130 119  
131 120 /// Verify following characters of an option
132   -template<typename T>
133   -bool valid_later_char(T c) {
134   - return std::isalnum(c, std::locale()) || c=='_' || c=='.' || c=='-';
  121 +template <typename T> bool valid_later_char(T c) {
  122 + return std::isalnum(c, std::locale()) || c == '_' || c == '.' || c == '-';
135 123 }
136 124  
137 125 /// Verify an option name
... ... @@ -146,16 +134,17 @@ inline bool valid_name_string(const std::string &amp;str) {
146 134  
147 135 /// Return a lower case version of a string
148 136 inline std::string to_lower(std::string str) {
149   - std::transform(std::begin(str), std::end(str), std::begin(str),
150   - [](const std::string::value_type &x){return std::tolower(x,std::locale());});
  137 + std::transform(std::begin(str), std::end(str), std::begin(str), [](const std::string::value_type &x) {
  138 + return std::tolower(x, std::locale());
  139 + });
151 140 return str;
152 141 }
153 142  
154 143 /// Split a string '"one two" "three"' into 'one two', 'three'
155 144 inline std::vector<std::string> split_up(std::string str) {
156   -
  145 +
157 146 std::vector<char> delims = {'\'', '\"'};
158   - auto find_ws = [](char ch){ return std::isspace<char>(ch , std::locale());};
  147 + auto find_ws = [](char ch) { return std::isspace<char>(ch, std::locale()); };
159 148 trim(str);
160 149  
161 150 std::vector<std::string> output;
... ... @@ -164,8 +153,8 @@ inline std::vector&lt;std::string&gt; split_up(std::string str) {
164 153 if(str[0] == '\'') {
165 154 auto end = str.find('\'', 1);
166 155 if(end != std::string::npos) {
167   - output.push_back(str.substr(1,end-1));
168   - str = str.substr(end+1);
  156 + output.push_back(str.substr(1, end - 1));
  157 + str = str.substr(end + 1);
169 158 } else {
170 159 output.push_back(str.substr(1));
171 160 str = "";
... ... @@ -173,8 +162,8 @@ inline std::vector&lt;std::string&gt; split_up(std::string str) {
173 162 } else if(str[0] == '\"') {
174 163 auto end = str.find('\"', 1);
175 164 if(end != std::string::npos) {
176   - output.push_back(str.substr(1,end-1));
177   - str = str.substr(end+1);
  165 + output.push_back(str.substr(1, end - 1));
  166 + str = str.substr(end + 1);
178 167 } else {
179 168 output.push_back(str.substr(1));
180 169 str = "";
... ... @@ -183,7 +172,7 @@ inline std::vector&lt;std::string&gt; split_up(std::string str) {
183 172 } else {
184 173 auto it = std::find_if(std::begin(str), std::end(str), find_ws);
185 174 if(it != std::end(str)) {
186   - std::string value = std::string(str.begin(),it);
  175 + std::string value = std::string(str.begin(), it);
187 176 output.push_back(value);
188 177 str = std::string(it, str.end());
189 178 } else {
... ...
include/CLI/Timer.hpp
... ... @@ -12,7 +12,7 @@
12 12 namespace CLI {
13 13  
14 14 class Timer {
15   -protected:
  15 + protected:
16 16 /// This is a typedef to make clocks easier to use
17 17 using clock = std::chrono::steady_clock;
18 18  
... ... @@ -20,7 +20,7 @@ protected:
20 20 using time_point = std::chrono::time_point<clock>;
21 21  
22 22 /// This is the type of a printing function, you can make your own
23   - using time_print_t = std::function<std::string (std::string, std::string)>;
  23 + using time_print_t = std::function<std::string(std::string, std::string)>;
24 24  
25 25 /// This is the title of the timer
26 26 std::string title_;
... ... @@ -30,31 +30,27 @@ protected:
30 30  
31 31 /// This is the starting point (when the timer was created)
32 32 time_point start_;
33   -
34   - /// This is the number of times cycles (print divides by this number)
35   - size_t cycles {1};
36 33  
37   -public:
  34 + /// This is the number of times cycles (print divides by this number)
  35 + size_t cycles{1};
38 36  
  37 + public:
39 38 /// Standard print function, this one is set by default
40   - static std::string Simple(std::string title, std::string time) {
41   - return title + ": " + time;
42   - }
  39 + static std::string Simple(std::string title, std::string time) { return title + ": " + time; }
43 40  
44 41 /// This is a fancy print function with --- headers
45 42 static std::string Big(std::string title, std::string time) {
46   - return std::string("-----------------------------------------\n")
47   - + "| " + title + " | Time = " + time + "\n"
48   - + "-----------------------------------------";
  43 + return std::string("-----------------------------------------\n") + "| " + title + " | Time = " + time + "\n" +
  44 + "-----------------------------------------";
49 45 }
50 46  
51   -public:
  47 + public:
52 48 /// Standard constructor, can set title and print function
53   - Timer(std::string title="Timer", time_print_t time_print = Simple)
  49 + Timer(std::string title = "Timer", time_print_t time_print = Simple)
54 50 : title_(std::move(title)), time_print_(std::move(time_print)), start_(clock::now()) {}
55 51  
56 52 /// Time a function by running it multiple times. Target time is the len to target.
57   - std::string time_it(std::function<void()> f, double target_time=1) {
  53 + std::string time_it(std::function<void()> f, double target_time = 1) {
58 54 time_point start = start_;
59 55 double total_time;
60 56  
... ... @@ -62,11 +58,11 @@ public:
62 58 size_t n = 0;
63 59 do {
64 60 f();
65   - std::chrono::duration<double> elapsed = clock::now() - start_;
  61 + std::chrono::duration<double> elapsed = clock::now() - start_;
66 62 total_time = elapsed.count();
67   - } while (n++ < 100 && total_time < target_time);
  63 + } while(n++ < 100 && total_time < target_time);
68 64  
69   - std::string out = make_time_str(total_time/n) + " for " + std::to_string(n) + " tries";
  65 + std::string out = make_time_str(total_time / n) + " for " + std::to_string(n) + " tries";
70 66 start_ = start;
71 67 return out;
72 68 }
... ... @@ -78,54 +74,48 @@ public:
78 74 double time = elapsed.count() / cycles;
79 75 return make_time_str(time);
80 76 }
81   -
  77 +
82 78 // LCOV_EXCL_START
83 79 std::string make_time_str(double time) const {
84   - auto print_it = [](double x, std::string unit){
  80 + auto print_it = [](double x, std::string unit) {
85 81 char buffer[50];
86 82 std::snprintf(buffer, 50, "%.5g", x);
87 83 return buffer + std::string(" ") + unit;
88 84 };
89   -
  85 +
90 86 if(time < .000001)
91   - return print_it(time*1000000000, "ns");
  87 + return print_it(time * 1000000000, "ns");
92 88 else if(time < .001)
93   - return print_it(time*1000000, "us");
  89 + return print_it(time * 1000000, "us");
94 90 else if(time < 1)
95   - return print_it(time*1000, "ms");
  91 + return print_it(time * 1000, "ms");
96 92 else
97 93 return print_it(time, "s");
98 94 }
99 95 // LCOV_EXCL_END
100 96  
101 97 /// This is the main function, it creates a string
102   - std::string to_string() const {
103   - return time_print_(title_, make_time_str());
104   - }
105   -
  98 + std::string to_string() const { return time_print_(title_, make_time_str()); }
  99 +
106 100 /// Division sets the number of cycles to divide by (no graphical change)
107   - Timer& operator / (size_t val) {cycles = val; return *this;}
  101 + Timer &operator/(size_t val) {
  102 + cycles = val;
  103 + return *this;
  104 + }
108 105 };
109 106  
110   -
111   -
112 107 /// This class prints out the time upon destruction
113 108 class AutoTimer : public Timer {
114   -public:
  109 + public:
115 110 /// Reimplementing the constructor is required in GCC 4.7
116   - AutoTimer(std::string title="Timer", time_print_t time_print = Simple)
117   - : Timer(title, time_print) {}
  111 + AutoTimer(std::string title = "Timer", time_print_t time_print = Simple) : Timer(title, time_print) {}
118 112 // GCC 4.7 does not support using inheriting constructors.
119 113  
120 114 /// This desctructor prints the string
121   - ~AutoTimer () {
122   - std::cout << to_string() << std::endl;
123   - }
  115 + ~AutoTimer() { std::cout << to_string() << std::endl; }
124 116 };
125 117  
126 118 } // namespace CLI
127 119  
128 120 /// This prints out the time if shifted into a std::cout like stream.
129   -inline std::ostream & operator<< (std::ostream& in, const CLI::Timer& timer) {
130   - return in << timer.to_string();
131   -}
  121 +inline std::ostream &operator<<(std::ostream &in, const CLI::Timer &timer) { return in << timer.to_string(); }
... ...
include/CLI/TypeTools.hpp
... ... @@ -14,126 +14,100 @@ namespace CLI {
14 14  
15 15 // Copied from C++14
16 16 #if __cplusplus < 201402L
17   -template< bool B, class T = void >
18   -using enable_if_t = typename std::enable_if<B,T>::type;
  17 +template <bool B, class T = void> using enable_if_t = typename std::enable_if<B, T>::type;
19 18 #else
20 19 // If your compiler supports C++14, you can use that definition instead
21 20 using std::enable_if_t;
22 21 #endif
23 22  
24   -template <typename T>
25   -struct is_vector {
26   - static const bool value = false;
27   -};
  23 +template <typename T> struct is_vector { static const bool value = false; };
28 24  
  25 +template <class T, class A> struct is_vector<std::vector<T, A>> { static bool const value = true; };
29 26  
30   -template<class T, class A>
31   -struct is_vector<std::vector<T, A> > {
32   - static bool const value = true;
33   -};
34   -
35   -template <typename T>
36   -struct is_bool {
37   - static const bool value = false;
38   -};
39   -
40   -template<>
41   -struct is_bool<bool> {
42   - static bool const value = true;
43   -};
  27 +template <typename T> struct is_bool { static const bool value = false; };
44 28  
  29 +template <> struct is_bool<bool> { static bool const value = true; };
45 30  
46 31 namespace detail {
47   - // Based generally on https://rmf.io/cxx11/almost-static-if
48   - /// Simple empty scoped class
49   - enum class enabler {};
50   -
51   - /// An instance to use in EnableIf
52   - constexpr enabler dummy = {};
53   -
54   -
55   - // Type name print
56   -
57   - /// Was going to be based on
58   - /// http://stackoverflow.com/questions/1055452/c-get-name-of-type-in-template
59   - /// But this is cleaner and works better in this case
60   -
61   - template<typename T,
62   - enable_if_t<std::is_integral<T>::value && std::is_signed<T>::value, detail::enabler> = detail::dummy>
63   - constexpr const char* type_name() {
64   - return "INT";
65   - }
66   -
67   - template<typename T,
68   - enable_if_t<std::is_integral<T>::value && std::is_unsigned<T>::value, detail::enabler> = detail::dummy>
69   - constexpr const char* type_name() {
70   - return "UINT";
71   - }
72   -
73   -
74   - template<typename T,
75   - enable_if_t<std::is_floating_point<T>::value, detail::enabler> = detail::dummy>
76   - constexpr const char* type_name() {
77   - return "FLOAT";
78   - }
79   -
80   -
81   - /// This one should not be used, since vector types print the internal type
82   - template<typename T,
83   - enable_if_t<is_vector<T>::value, detail::enabler> = detail::dummy>
84   - constexpr const char* type_name() {
85   - return "VECTOR";
86   - }
87   -
88   -
89   - template<typename T,
90   - enable_if_t<!std::is_floating_point<T>::value && !std::is_integral<T>::value && !is_vector<T>::value
91   - , detail::enabler> = detail::dummy>
92   - constexpr const char* type_name() {
93   - return "TEXT";
94   - }
95   -
96   -
97   -
98   - // Lexical cast
99   -
100   -
101   - /// Integers
102   - template<typename T, enable_if_t<std::is_integral<T>::value, detail::enabler> = detail::dummy>
103   - bool lexical_cast(std::string input, T& output) {
104   - try{
105   - output = static_cast<T>(std::stoll(input));
106   - return true;
107   - } catch (const std::invalid_argument&) {
108   - return false;
109   - } catch (const std::out_of_range&) {
110   - return false;
111   - }
112   - }
113   -
114   - /// Floats
115   - template<typename T, enable_if_t<std::is_floating_point<T>::value, detail::enabler> = detail::dummy>
116   - bool lexical_cast(std::string input, T& output) {
117   - try{
118   - output =static_cast<T>(std::stold(input));
119   - return true;
120   - } catch (const std::invalid_argument&) {
121   - return false;
122   - } catch (const std::out_of_range&) {
123   - return false;
124   - }
  32 +// Based generally on https://rmf.io/cxx11/almost-static-if
  33 +/// Simple empty scoped class
  34 +enum class enabler {};
  35 +
  36 +/// An instance to use in EnableIf
  37 +constexpr enabler dummy = {};
  38 +
  39 +// Type name print
  40 +
  41 +/// Was going to be based on
  42 +/// http://stackoverflow.com/questions/1055452/c-get-name-of-type-in-template
  43 +/// But this is cleaner and works better in this case
  44 +
  45 +template <typename T,
  46 + enable_if_t<std::is_integral<T>::value && std::is_signed<T>::value, detail::enabler> = detail::dummy>
  47 +constexpr const char *type_name() {
  48 + return "INT";
  49 +}
  50 +
  51 +template <typename T,
  52 + enable_if_t<std::is_integral<T>::value && std::is_unsigned<T>::value, detail::enabler> = detail::dummy>
  53 +constexpr const char *type_name() {
  54 + return "UINT";
  55 +}
  56 +
  57 +template <typename T, enable_if_t<std::is_floating_point<T>::value, detail::enabler> = detail::dummy>
  58 +constexpr const char *type_name() {
  59 + return "FLOAT";
  60 +}
  61 +
  62 +/// This one should not be used, since vector types print the internal type
  63 +template <typename T, enable_if_t<is_vector<T>::value, detail::enabler> = detail::dummy>
  64 +constexpr const char *type_name() {
  65 + return "VECTOR";
  66 +}
  67 +
  68 +template <typename T,
  69 + enable_if_t<!std::is_floating_point<T>::value && !std::is_integral<T>::value && !is_vector<T>::value,
  70 + detail::enabler> = detail::dummy>
  71 +constexpr const char *type_name() {
  72 + return "TEXT";
  73 +}
  74 +
  75 +// Lexical cast
  76 +
  77 +/// Integers
  78 +template <typename T, enable_if_t<std::is_integral<T>::value, detail::enabler> = detail::dummy>
  79 +bool lexical_cast(std::string input, T &output) {
  80 + try {
  81 + output = static_cast<T>(std::stoll(input));
  82 + return true;
  83 + } catch(const std::invalid_argument &) {
  84 + return false;
  85 + } catch(const std::out_of_range &) {
  86 + return false;
125 87 }
  88 +}
126 89  
127   -
128   - /// String and similar
129   - template<typename T,
130   - enable_if_t<!std::is_floating_point<T>::value && !std::is_integral<T>::value
131   - , detail::enabler> = detail::dummy>
132   - bool lexical_cast(std::string input, T& output) {
133   - output = input;
  90 +/// Floats
  91 +template <typename T, enable_if_t<std::is_floating_point<T>::value, detail::enabler> = detail::dummy>
  92 +bool lexical_cast(std::string input, T &output) {
  93 + try {
  94 + output = static_cast<T>(std::stold(input));
134 95 return true;
  96 + } catch(const std::invalid_argument &) {
  97 + return false;
  98 + } catch(const std::out_of_range &) {
  99 + return false;
135 100 }
136   -
  101 +}
  102 +
  103 +/// String and similar
  104 +template <
  105 + typename T,
  106 + enable_if_t<!std::is_floating_point<T>::value && !std::is_integral<T>::value, detail::enabler> = detail::dummy>
  107 +bool lexical_cast(std::string input, T &output) {
  108 + output = input;
  109 + return true;
  110 +}
137 111  
138 112 } // namespace detail
139 113 } // namespace CLI
... ...
include/CLI/Validators.hpp
... ... @@ -16,7 +16,6 @@
16 16  
17 17 namespace CLI {
18 18  
19   -
20 19 /// @defgroup validator_group Validators
21 20 /// @brief Some validators that are provided
22 21 ///
... ... @@ -25,13 +24,13 @@ namespace CLI {
25 24  
26 25 /// Check for an existing file
27 26 inline bool ExistingFile(std::string filename) {
28   - struct stat buffer;
29   - bool exist = stat(filename.c_str(), &buffer) == 0;
  27 + struct stat buffer;
  28 + bool exist = stat(filename.c_str(), &buffer) == 0;
30 29 bool is_dir = (buffer.st_mode & S_IFDIR) != 0;
31 30 if(!exist) {
32 31 std::cerr << "File does not exist: " << filename << std::endl;
33 32 return false;
34   - } else if (is_dir) {
  33 + } else if(is_dir) {
35 34 std::cerr << "File is actually a directory: " << filename << std::endl;
36 35 return false;
37 36 } else {
... ... @@ -41,13 +40,13 @@ inline bool ExistingFile(std::string filename) {
41 40  
42 41 /// Check for an existing directory
43 42 inline bool ExistingDirectory(std::string filename) {
44   - struct stat buffer;
45   - bool exist = stat(filename.c_str(), &buffer) == 0;
  43 + struct stat buffer;
  44 + bool exist = stat(filename.c_str(), &buffer) == 0;
46 45 bool is_dir = (buffer.st_mode & S_IFDIR) != 0;
47 46 if(!exist) {
48 47 std::cerr << "Directory does not exist: " << filename << std::endl;
49 48 return false;
50   - } else if (is_dir) {
  49 + } else if(is_dir) {
51 50 return true;
52 51 } else {
53 52 std::cerr << "Directory is actually a file: " << filename << std::endl;
... ... @@ -55,11 +54,10 @@ inline bool ExistingDirectory(std::string filename) {
55 54 }
56 55 }
57 56  
58   -
59 57 /// Check for a non-existing path
60 58 inline bool NonexistentPath(std::string filename) {
61   - struct stat buffer;
62   - bool exist = stat(filename.c_str(), &buffer) == 0;
  59 + struct stat buffer;
  60 + bool exist = stat(filename.c_str(), &buffer) == 0;
63 61 if(!exist) {
64 62 return true;
65 63 } else {
... ... @@ -69,9 +67,8 @@ inline bool NonexistentPath(std::string filename) {
69 67 }
70 68  
71 69 /// Produce a range validator function
72   -template<typename T>
73   -std::function<bool(std::string)> Range(T min, T max) {
74   - return [min, max](std::string input){
  70 +template <typename T> std::function<bool(std::string)> Range(T min, T max) {
  71 + return [min, max](std::string input) {
75 72 T val;
76 73 detail::lexical_cast(input, val);
77 74 return val >= min && val <= max;
... ... @@ -79,10 +76,7 @@ std::function&lt;bool(std::string)&gt; Range(T min, T max) {
79 76 }
80 77  
81 78 /// Range of one value is 0 to value
82   -template<typename T>
83   -std::function<bool(std::string)> Range(T max) {
84   - return Range(static_cast<T>(0), max);
85   -}
  79 +template <typename T> std::function<bool(std::string)> Range(T max) { return Range(static_cast<T>(0), max); }
86 80  
87 81 /// @}
88 82  
... ...
tests/.syntastic_cpp_config
1   --I../build/googletest-src/googletest/include/
2   --I../build/googletest-src/googlemock/include/
  1 +- I../ build / googletest - src / googletest / include / -I../ build / googletest - src / googlemock / include /
... ...
tests/AppTest.cpp
1 1 #include "app_helper.hpp"
2 2 #include <cstdlib>
3 3  
4   -
5 4 TEST_F(TApp, OneFlagShort) {
6 5 app.add_flag("-c,--count");
7 6 args = {"-c"};
8 7 run();
9   - EXPECT_EQ((size_t) 1, app.count("-c"));
10   - EXPECT_EQ((size_t) 1, app.count("--count"));
  8 + EXPECT_EQ((size_t)1, app.count("-c"));
  9 + EXPECT_EQ((size_t)1, app.count("--count"));
11 10 }
12 11  
13 12 TEST_F(TApp, CountNonExist) {
... ... @@ -21,8 +20,8 @@ TEST_F(TApp, OneFlagLong) {
21 20 app.add_flag("-c,--count");
22 21 args = {"--count"};
23 22 run();
24   - EXPECT_EQ((size_t) 1, app.count("-c"));
25   - EXPECT_EQ((size_t) 1, app.count("--count"));
  23 + EXPECT_EQ((size_t)1, app.count("-c"));
  24 + EXPECT_EQ((size_t)1, app.count("--count"));
26 25 }
27 26  
28 27 TEST_F(TApp, DashedOptions) {
... ... @@ -32,11 +31,10 @@ TEST_F(TApp, DashedOptions) {
32 31  
33 32 args = {"-c", "--q", "--this", "--that"};
34 33 run();
35   - EXPECT_EQ((size_t) 1, app.count("-c"));
36   - EXPECT_EQ((size_t) 1, app.count("--q"));
37   - EXPECT_EQ((size_t) 2, app.count("--this"));
38   - EXPECT_EQ((size_t) 2, app.count("--that"));
39   -
  34 + EXPECT_EQ((size_t)1, app.count("-c"));
  35 + EXPECT_EQ((size_t)1, app.count("--q"));
  36 + EXPECT_EQ((size_t)2, app.count("--this"));
  37 + EXPECT_EQ((size_t)2, app.count("--that"));
40 38 }
41 39  
42 40 TEST_F(TApp, OneFlagRef) {
... ... @@ -44,8 +42,8 @@ TEST_F(TApp, OneFlagRef) {
44 42 app.add_flag("-c,--count", ref);
45 43 args = {"--count"};
46 44 run();
47   - EXPECT_EQ((size_t) 1, app.count("-c"));
48   - EXPECT_EQ((size_t) 1, app.count("--count"));
  45 + EXPECT_EQ((size_t)1, app.count("-c"));
  46 + EXPECT_EQ((size_t)1, app.count("--count"));
49 47 EXPECT_EQ(1, ref);
50 48 }
51 49  
... ... @@ -54,8 +52,8 @@ TEST_F(TApp, OneString) {
54 52 app.add_option("-s,--string", str);
55 53 args = {"--string", "mystring"};
56 54 run();
57   - EXPECT_EQ((size_t) 1, app.count("-s"));
58   - EXPECT_EQ((size_t) 1, app.count("--string"));
  55 + EXPECT_EQ((size_t)1, app.count("-s"));
  56 + EXPECT_EQ((size_t)1, app.count("--string"));
59 57 EXPECT_EQ(str, "mystring");
60 58 }
61 59  
... ... @@ -64,29 +62,28 @@ TEST_F(TApp, OneStringEqualVersion) {
64 62 app.add_option("-s,--string", str);
65 63 args = {"--string=mystring"};
66 64 run();
67   - EXPECT_EQ((size_t) 1, app.count("-s"));
68   - EXPECT_EQ((size_t) 1, app.count("--string"));
  65 + EXPECT_EQ((size_t)1, app.count("-s"));
  66 + EXPECT_EQ((size_t)1, app.count("--string"));
69 67 EXPECT_EQ(str, "mystring");
70 68 }
71 69  
72   -
73 70 TEST_F(TApp, TogetherInt) {
74 71 int i;
75 72 app.add_option("-i,--int", i);
76 73 args = {"-i4"};
77 74 run();
78   - EXPECT_EQ((size_t) 1, app.count("--int"));
79   - EXPECT_EQ((size_t) 1, app.count("-i"));
  75 + EXPECT_EQ((size_t)1, app.count("--int"));
  76 + EXPECT_EQ((size_t)1, app.count("-i"));
80 77 EXPECT_EQ(i, 4);
81 78 }
82 79  
83 80 TEST_F(TApp, SepInt) {
84 81 int i;
85 82 app.add_option("-i,--int", i);
86   - args = {"-i","4"};
  83 + args = {"-i", "4"};
87 84 run();
88   - EXPECT_EQ((size_t) 1, app.count("--int"));
89   - EXPECT_EQ((size_t) 1, app.count("-i"));
  85 + EXPECT_EQ((size_t)1, app.count("--int"));
  86 + EXPECT_EQ((size_t)1, app.count("-i"));
90 87 EXPECT_EQ(i, 4);
91 88 }
92 89  
... ... @@ -95,18 +92,17 @@ TEST_F(TApp, OneStringAgain) {
95 92 app.add_option("-s,--string", str);
96 93 args = {"--string", "mystring"};
97 94 run();
98   - EXPECT_EQ((size_t) 1, app.count("-s"));
99   - EXPECT_EQ((size_t) 1, app.count("--string"));
  95 + EXPECT_EQ((size_t)1, app.count("-s"));
  96 + EXPECT_EQ((size_t)1, app.count("--string"));
100 97 EXPECT_EQ(str, "mystring");
101 98 }
102 99  
103   -
104 100 TEST_F(TApp, DefaultStringAgain) {
105 101 std::string str = "previous";
106 102 app.add_option("-s,--string", str);
107 103 run();
108   - EXPECT_EQ((size_t) 0, app.count("-s"));
109   - EXPECT_EQ((size_t) 0, app.count("--string"));
  104 + EXPECT_EQ((size_t)0, app.count("-s"));
  105 + EXPECT_EQ((size_t)0, app.count("--string"));
110 106 EXPECT_EQ(str, "previous");
111 107 }
112 108  
... ... @@ -132,14 +128,13 @@ TEST_F(TApp, LotsOfFlags) {
132 128 app.add_flag("-A");
133 129 app.add_flag("-b");
134 130  
135   - args = {"-a","-b","-aA"};
  131 + args = {"-a", "-b", "-aA"};
136 132 run();
137   - EXPECT_EQ((size_t) 2, app.count("-a"));
138   - EXPECT_EQ((size_t) 1, app.count("-b"));
139   - EXPECT_EQ((size_t) 1, app.count("-A"));
  133 + EXPECT_EQ((size_t)2, app.count("-a"));
  134 + EXPECT_EQ((size_t)1, app.count("-b"));
  135 + EXPECT_EQ((size_t)1, app.count("-A"));
140 136 }
141 137  
142   -
143 138 TEST_F(TApp, BoolAndIntFlags) {
144 139  
145 140 bool bflag;
... ... @@ -154,7 +149,7 @@ TEST_F(TApp, BoolAndIntFlags) {
154 149 run();
155 150 EXPECT_TRUE(bflag);
156 151 EXPECT_EQ(1, iflag);
157   - EXPECT_EQ((unsigned int) 1, uflag);
  152 + EXPECT_EQ((unsigned int)1, uflag);
158 153  
159 154 app.reset();
160 155  
... ... @@ -168,7 +163,7 @@ TEST_F(TApp, BoolAndIntFlags) {
168 163 run();
169 164 EXPECT_FALSE(bflag);
170 165 EXPECT_EQ(3, iflag);
171   - EXPECT_EQ((unsigned int) 2, uflag);
  166 + EXPECT_EQ((unsigned int)2, uflag);
172 167 }
173 168  
174 169 TEST_F(TApp, ShortOpts) {
... ... @@ -178,13 +173,15 @@ TEST_F(TApp, ShortOpts) {
178 173 app.add_flag("-z", funnyint);
179 174 app.add_option("-y", someopt);
180 175  
181   - args = {"-zzyzyz",};
  176 + args = {
  177 + "-zzyzyz",
  178 + };
182 179  
183 180 run();
184 181  
185   - EXPECT_EQ((size_t) 2, app.count("-z"));
186   - EXPECT_EQ((size_t) 1, app.count("-y"));
187   - EXPECT_EQ((unsigned long long) 2, funnyint);
  182 + EXPECT_EQ((size_t)2, app.count("-z"));
  183 + EXPECT_EQ((size_t)1, app.count("-y"));
  184 + EXPECT_EQ((unsigned long long)2, funnyint);
188 185 EXPECT_EQ("zyz", someopt);
189 186 }
190 187  
... ... @@ -200,8 +197,8 @@ TEST_F(TApp, DefaultOpts) {
200 197  
201 198 run();
202 199  
203   - EXPECT_EQ((size_t) 1, app.count("i"));
204   - EXPECT_EQ((size_t) 1, app.count("-s"));
  200 + EXPECT_EQ((size_t)1, app.count("i"));
  201 + EXPECT_EQ((size_t)1, app.count("-s"));
205 202 EXPECT_EQ(2, i);
206 203 EXPECT_EQ("9", s);
207 204 }
... ... @@ -224,7 +221,6 @@ TEST_F(TApp, RequiredFlags) {
224 221 app.reset();
225 222 args = {"-a", "-b"};
226 223 run();
227   -
228 224 }
229 225  
230 226 TEST_F(TApp, Positionals) {
... ... @@ -234,17 +230,16 @@ TEST_F(TApp, Positionals) {
234 230 app.add_option("posit1", posit1);
235 231 app.add_option("posit2", posit2);
236 232  
237   - args = {"thing1","thing2"};
  233 + args = {"thing1", "thing2"};
238 234  
239 235 run();
240 236  
241   - EXPECT_EQ((size_t) 1, app.count("posit1"));
242   - EXPECT_EQ((size_t) 1, app.count("posit2"));
  237 + EXPECT_EQ((size_t)1, app.count("posit1"));
  238 + EXPECT_EQ((size_t)1, app.count("posit2"));
243 239 EXPECT_EQ("thing1", posit1);
244 240 EXPECT_EQ("thing2", posit2);
245 241 }
246 242  
247   -
248 243 TEST_F(TApp, ForcedPositional) {
249 244 std::vector<std::string> posit;
250 245 auto one = app.add_flag("--one");
... ... @@ -266,7 +261,6 @@ TEST_F(TApp, ForcedPositional) {
266 261 EXPECT_EQ(answers2, posit);
267 262 }
268 263  
269   -
270 264 TEST_F(TApp, MixedPositionals) {
271 265  
272 266 int positional_int;
... ... @@ -274,12 +268,12 @@ TEST_F(TApp, MixedPositionals) {
274 268 app.add_option("posit1,--posit1", positional_int, "");
275 269 app.add_option("posit2,--posit2", positional_string, "");
276 270  
277   - args = {"--posit2","thing2","7"};
  271 + args = {"--posit2", "thing2", "7"};
278 272  
279 273 run();
280 274  
281   - EXPECT_EQ((size_t) 1, app.count("posit2"));
282   - EXPECT_EQ((size_t) 1, app.count("--posit1"));
  275 + EXPECT_EQ((size_t)1, app.count("posit2"));
  276 + EXPECT_EQ((size_t)1, app.count("--posit1"));
283 277 EXPECT_EQ(7, positional_int);
284 278 EXPECT_EQ("thing2", positional_string);
285 279 }
... ... @@ -311,24 +305,22 @@ TEST_F(TApp, Reset) {
311 305  
312 306 run();
313 307  
314   - EXPECT_EQ((size_t) 1, app.count("--simple"));
315   - EXPECT_EQ((size_t) 1, app.count("-d"));
  308 + EXPECT_EQ((size_t)1, app.count("--simple"));
  309 + EXPECT_EQ((size_t)1, app.count("-d"));
316 310 EXPECT_DOUBLE_EQ(1.2, doub);
317 311  
318 312 app.reset();
319 313  
320   - EXPECT_EQ((size_t) 0, app.count("--simple"));
321   - EXPECT_EQ((size_t) 0, app.count("-d"));
322   -
  314 + EXPECT_EQ((size_t)0, app.count("--simple"));
  315 + EXPECT_EQ((size_t)0, app.count("-d"));
  316 +
323 317 run();
324 318  
325   - EXPECT_EQ((size_t) 1, app.count("--simple"));
326   - EXPECT_EQ((size_t) 1, app.count("-d"));
  319 + EXPECT_EQ((size_t)1, app.count("--simple"));
  320 + EXPECT_EQ((size_t)1, app.count("-d"));
327 321 EXPECT_DOUBLE_EQ(1.2, doub);
328   -
329 322 }
330 323  
331   -
332 324 TEST_F(TApp, RemoveOption) {
333 325 app.add_flag("--one");
334 326 auto opt = app.add_flag("--two");
... ... @@ -354,7 +346,6 @@ TEST_F(TApp, FileNotExists) {
354 346  
355 347 app.reset();
356 348  
357   -
358 349 bool ok = static_cast<bool>(std::ofstream(myfile.c_str()).put('a')); // create file
359 350 EXPECT_TRUE(ok);
360 351 EXPECT_THROW(run(), CLI::ValidationError);
... ... @@ -388,7 +379,7 @@ TEST_F(TApp, InSet) {
388 379  
389 380 std::string choice;
390 381 app.add_set("-q,--quick", choice, {"one", "two", "three"});
391   -
  382 +
392 383 args = {"--quick", "two"};
393 384  
394 385 run();
... ... @@ -404,7 +395,7 @@ TEST_F(TApp, InIntSet) {
404 395  
405 396 int choice;
406 397 app.add_set("-q,--quick", choice, {1, 2, 3});
407   -
  398 +
408 399 args = {"--quick", "2"};
409 400  
410 401 run();
... ... @@ -420,7 +411,7 @@ TEST_F(TApp, FailSet) {
420 411  
421 412 int choice;
422 413 app.add_set("-q,--quick", choice, {1, 2, 3});
423   -
  414 +
424 415 args = {"--quick", "3", "--quick=2"};
425 416 EXPECT_THROW(run(), CLI::ConversionError);
426 417  
... ... @@ -430,12 +421,11 @@ TEST_F(TApp, FailSet) {
430 421 EXPECT_THROW(run(), CLI::ConversionError);
431 422 }
432 423  
433   -
434 424 TEST_F(TApp, InSetIgnoreCase) {
435 425  
436 426 std::string choice;
437 427 app.add_set_ignore_case("-q,--quick", choice, {"one", "Two", "THREE"});
438   -
  428 +
439 429 args = {"--quick", "One"};
440 430 run();
441 431 EXPECT_EQ("one", choice);
... ... @@ -450,7 +440,6 @@ TEST_F(TApp, InSetIgnoreCase) {
450 440 run();
451 441 EXPECT_EQ("THREE", choice); // Keeps caps from set
452 442  
453   -
454 443 app.reset();
455 444 args = {"--quick", "four"};
456 445 EXPECT_THROW(run(), CLI::ConversionError);
... ... @@ -458,54 +447,50 @@ TEST_F(TApp, InSetIgnoreCase) {
458 447 app.reset();
459 448 args = {"--quick=one", "--quick=two"};
460 449 EXPECT_THROW(run(), CLI::ConversionError);
461   -
462 450 }
463 451  
464 452 TEST_F(TApp, VectorFixedString) {
465 453 std::vector<std::string> strvec;
466 454 std::vector<std::string> answer{"mystring", "mystring2", "mystring3"};
467 455  
468   - CLI::Option* opt = app.add_option("-s,--string", strvec)->expected(3);
  456 + CLI::Option *opt = app.add_option("-s,--string", strvec)->expected(3);
469 457 EXPECT_EQ(3, opt->get_expected());
470   -
  458 +
471 459 args = {"--string", "mystring", "mystring2", "mystring3"};
472 460 run();
473   - EXPECT_EQ((size_t) 3, app.count("--string"));
  461 + EXPECT_EQ((size_t)3, app.count("--string"));
474 462 EXPECT_EQ(answer, strvec);
475 463 }
476 464  
477   -
478   -
479 465 TEST_F(TApp, VectorUnlimString) {
480 466 std::vector<std::string> strvec;
481 467 std::vector<std::string> answer{"mystring", "mystring2", "mystring3"};
482 468  
483   - CLI::Option* opt = app.add_option("-s,--string", strvec);
  469 + CLI::Option *opt = app.add_option("-s,--string", strvec);
484 470 EXPECT_EQ(-1, opt->get_expected());
485 471  
486 472 args = {"--string", "mystring", "mystring2", "mystring3"};
487 473 run();
488   - EXPECT_EQ((size_t) 3, app.count("--string"));
  474 + EXPECT_EQ((size_t)3, app.count("--string"));
489 475 EXPECT_EQ(answer, strvec);
490   -
  476 +
491 477 app.reset();
492 478 args = {"-s", "mystring", "mystring2", "mystring3"};
493 479 run();
494   - EXPECT_EQ((size_t) 3, app.count("--string"));
  480 + EXPECT_EQ((size_t)3, app.count("--string"));
495 481 EXPECT_EQ(answer, strvec);
496 482 }
497 483  
498   -
499 484 TEST_F(TApp, VectorFancyOpts) {
500 485 std::vector<std::string> strvec;
501 486 std::vector<std::string> answer{"mystring", "mystring2", "mystring3"};
502 487  
503   - CLI::Option* opt = app.add_option("-s,--string", strvec)->required()->expected(3);
  488 + CLI::Option *opt = app.add_option("-s,--string", strvec)->required()->expected(3);
504 489 EXPECT_EQ(3, opt->get_expected());
505 490  
506 491 args = {"--string", "mystring", "mystring2", "mystring3"};
507 492 run();
508   - EXPECT_EQ((size_t) 3, app.count("--string"));
  493 + EXPECT_EQ((size_t)3, app.count("--string"));
509 494 EXPECT_EQ(answer, strvec);
510 495  
511 496 app.reset();
... ... @@ -517,7 +502,7 @@ TEST_F(TApp, VectorFancyOpts) {
517 502 }
518 503  
519 504 TEST_F(TApp, RequiresFlags) {
520   - CLI::Option* opt = app.add_flag("-s,--string");
  505 + CLI::Option *opt = app.add_flag("-s,--string");
521 506 app.add_flag("--both")->requires(opt);
522 507  
523 508 run();
... ... @@ -535,9 +520,8 @@ TEST_F(TApp, RequiresFlags) {
535 520 EXPECT_THROW(run(), CLI::RequiresError);
536 521 }
537 522  
538   -
539 523 TEST_F(TApp, ExcludesFlags) {
540   - CLI::Option* opt = app.add_flag("-s,--string");
  524 + CLI::Option *opt = app.add_flag("-s,--string");
541 525 app.add_flag("--nostr")->excludes(opt);
542 526  
543 527 run();
... ... @@ -560,9 +544,9 @@ TEST_F(TApp, ExcludesFlags) {
560 544 }
561 545  
562 546 TEST_F(TApp, ExcludesMixedFlags) {
563   - CLI::Option* opt1 = app.add_flag("--opt1");
  547 + CLI::Option *opt1 = app.add_flag("--opt1");
564 548 app.add_flag("--opt2");
565   - CLI::Option* opt3 = app.add_flag("--opt3");
  549 + CLI::Option *opt3 = app.add_flag("--opt3");
566 550 app.add_flag("--no")->excludes(opt1, "--opt2", opt3);
567 551  
568 552 run();
... ... @@ -585,9 +569,9 @@ TEST_F(TApp, ExcludesMixedFlags) {
585 569 }
586 570  
587 571 TEST_F(TApp, RequiresMultiFlags) {
588   - CLI::Option* opt1 = app.add_flag("--opt1");
589   - CLI::Option* opt2 = app.add_flag("--opt2");
590   - CLI::Option* opt3 = app.add_flag("--opt3");
  572 + CLI::Option *opt1 = app.add_flag("--opt1");
  573 + CLI::Option *opt2 = app.add_flag("--opt2");
  574 + CLI::Option *opt3 = app.add_flag("--opt3");
591 575 app.add_flag("--optall")->requires(opt1, opt2, opt3);
592 576  
593 577 run();
... ... @@ -618,7 +602,7 @@ TEST_F(TApp, RequiresMultiFlags) {
618 602 }
619 603  
620 604 TEST_F(TApp, RequiresMixedFlags) {
621   - CLI::Option* opt1 = app.add_flag("--opt1");
  605 + CLI::Option *opt1 = app.add_flag("--opt1");
622 606 app.add_flag("--opt2");
623 607 app.add_flag("--opt3");
624 608 app.add_flag("--optall")->requires(opt1, "--opt2", "--opt3");
... ... @@ -651,8 +635,8 @@ TEST_F(TApp, RequiresMixedFlags) {
651 635 }
652 636  
653 637 TEST_F(TApp, RequiresChainedFlags) {
654   - CLI::Option* opt1 = app.add_flag("--opt1");
655   - CLI::Option* opt2 = app.add_flag("--opt2")->requires(opt1);
  638 + CLI::Option *opt1 = app.add_flag("--opt1");
  639 + CLI::Option *opt2 = app.add_flag("--opt2")->requires(opt1);
656 640 app.add_flag("--opt3")->requires(opt2);
657 641  
658 642 run();
... ... @@ -690,13 +674,13 @@ TEST_F(TApp, Env) {
690 674  
691 675 put_env("CLI11_TEST_ENV_TMP", "2");
692 676  
693   - int val=1;
694   - CLI::Option* vopt = app.add_option("--tmp", val)->envname("CLI11_TEST_ENV_TMP");
  677 + int val = 1;
  678 + CLI::Option *vopt = app.add_option("--tmp", val)->envname("CLI11_TEST_ENV_TMP");
695 679  
696 680 run();
697 681  
698 682 EXPECT_EQ(2, val);
699   - EXPECT_EQ((size_t) 1, vopt->count());
  683 + EXPECT_EQ((size_t)1, vopt->count());
700 684  
701 685 app.reset();
702 686 vopt->required();
... ... @@ -708,8 +692,8 @@ TEST_F(TApp, Env) {
708 692 }
709 693  
710 694 TEST_F(TApp, RangeInt) {
711   - int x=0;
712   - app.add_option("--one", x)->check(CLI::Range(3,6));
  695 + int x = 0;
  696 + app.add_option("--one", x)->check(CLI::Range(3, 6));
713 697  
714 698 args = {"--one=1"};
715 699 EXPECT_THROW(run(), CLI::ValidationError);
... ... @@ -733,9 +717,9 @@ TEST_F(TApp, RangeInt) {
733 717  
734 718 TEST_F(TApp, RangeDouble) {
735 719  
736   - double x=0;
  720 + double x = 0;
737 721 /// Note that this must be a double in Range, too
738   - app.add_option("--one", x)->check(CLI::Range(3.0,6.0));
  722 + app.add_option("--one", x)->check(CLI::Range(3.0, 6.0));
739 723  
740 724 args = {"--one=1"};
741 725 EXPECT_THROW(run(), CLI::ValidationError);
... ... @@ -768,10 +752,9 @@ TEST_F(TApp, AllowExtras) {
768 752  
769 753 args = {"-x", "-f"};
770 754 std::vector<std::string> left_over;
771   - EXPECT_NO_THROW({left_over = run();});
  755 + EXPECT_NO_THROW({ left_over = run(); });
772 756 EXPECT_TRUE(val);
773 757 EXPECT_EQ(std::vector<std::string>({"-x"}), left_over);
774   -
775 758 }
776 759  
777 760 TEST_F(TApp, AllowExtrasOrder) {
... ... @@ -780,14 +763,13 @@ TEST_F(TApp, AllowExtrasOrder) {
780 763  
781 764 args = {"-x", "-f"};
782 765 std::vector<std::string> left_over;
783   - EXPECT_NO_THROW({left_over = run();});
  766 + EXPECT_NO_THROW({ left_over = run(); });
784 767 EXPECT_EQ(std::vector<std::string>({"-f", "-x"}), left_over);
785 768 app.reset();
786 769  
787 770 std::vector<std::string> left_over_2;
788 771 left_over_2 = app.parse(left_over);
789 772 EXPECT_EQ(left_over, left_over_2);
790   -
791 773 }
792 774  
793 775 // Test horrible error
... ...
tests/CreationTest.cpp
... ... @@ -53,10 +53,9 @@ TEST_F(TApp, AddingMultipleInfPositionals) {
53 53 EXPECT_THROW(run(), CLI::InvalidError);
54 54 }
55 55  
56   -
57 56 TEST_F(TApp, AddingMultipleInfPositionalsSubcom) {
58 57 std::vector<std::string> one, two;
59   - CLI::App* below = app.add_subcommand("below");
  58 + CLI::App *below = app.add_subcommand("below");
60 59 below->add_option("one", one);
61 60 below->add_option("two", two);
62 61  
... ... @@ -84,28 +83,26 @@ TEST_F(TApp, MultipleSubcomMatchingWithCaseFirst) {
84 83 TEST_F(TApp, MultipleSubcomMatchingWithCaseInplace) {
85 84 app.add_subcommand("first");
86 85 auto first = app.add_subcommand("fIrst");
87   -
  86 +
88 87 EXPECT_THROW(first->ignore_case(), CLI::OptionAlreadyAdded);
89 88 }
90 89  
91 90 TEST_F(TApp, MultipleSubcomMatchingWithCaseInplace2) {
92 91 auto first = app.add_subcommand("first");
93 92 app.add_subcommand("fIrst");
94   -
  93 +
95 94 EXPECT_THROW(first->ignore_case(), CLI::OptionAlreadyAdded);
96 95 }
97 96  
98 97 TEST_F(TApp, MultipleSubcomNoMatchingInplace2) {
99 98 auto first = app.add_subcommand("first");
100 99 auto second = app.add_subcommand("second");
101   -
  100 +
102 101 EXPECT_NO_THROW(first->ignore_case());
103 102 EXPECT_NO_THROW(second->ignore_case());
104 103 }
105 104  
106   -TEST_F(TApp, IncorrectConstructionFlagPositional1) {
107   - EXPECT_THROW(app.add_flag("cat"), CLI::IncorrectConstruction);
108   -}
  105 +TEST_F(TApp, IncorrectConstructionFlagPositional1) { EXPECT_THROW(app.add_flag("cat"), CLI::IncorrectConstruction); }
109 106  
110 107 TEST_F(TApp, IncorrectConstructionFlagPositional2) {
111 108 int x;
... ... @@ -142,40 +139,40 @@ TEST_F(TApp, IncorrectConstructionVectorAsFlag) {
142 139  
143 140 TEST_F(TApp, IncorrectConstructionRequiresCannotFind) {
144 141 auto cat = app.add_flag("--cat");
145   - EXPECT_THROW(cat->requires("--nothing"),CLI::IncorrectConstruction);
  142 + EXPECT_THROW(cat->requires("--nothing"), CLI::IncorrectConstruction);
146 143 }
147 144  
148 145 TEST_F(TApp, IncorrectConstructionExcludesCannotFind) {
149 146 auto cat = app.add_flag("--cat");
150   - EXPECT_THROW(cat->excludes("--nothing"),CLI::IncorrectConstruction);
  147 + EXPECT_THROW(cat->excludes("--nothing"), CLI::IncorrectConstruction);
151 148 }
152 149  
153 150 TEST_F(TApp, IncorrectConstructionDuplicateRequires) {
154 151 auto cat = app.add_flag("--cat");
155 152 auto other = app.add_flag("--other");
156 153 ASSERT_NO_THROW(cat->requires(other));
157   - EXPECT_THROW(cat->requires(other),CLI::OptionAlreadyAdded);
  154 + EXPECT_THROW(cat->requires(other), CLI::OptionAlreadyAdded);
158 155 }
159 156  
160 157 TEST_F(TApp, IncorrectConstructionDuplicateRequiresTxt) {
161 158 auto cat = app.add_flag("--cat");
162 159 app.add_flag("--other");
163 160 ASSERT_NO_THROW(cat->requires("--other"));
164   - EXPECT_THROW(cat->requires("--other"),CLI::OptionAlreadyAdded);
  161 + EXPECT_THROW(cat->requires("--other"), CLI::OptionAlreadyAdded);
165 162 }
166 163  
167 164 TEST_F(TApp, IncorrectConstructionDuplicateExcludes) {
168 165 auto cat = app.add_flag("--cat");
169 166 auto other = app.add_flag("--other");
170 167 ASSERT_NO_THROW(cat->excludes(other));
171   - EXPECT_THROW(cat->excludes(other),CLI::OptionAlreadyAdded);
  168 + EXPECT_THROW(cat->excludes(other), CLI::OptionAlreadyAdded);
172 169 }
173 170  
174 171 TEST_F(TApp, IncorrectConstructionDuplicateExcludesTxt) {
175 172 auto cat = app.add_flag("--cat");
176 173 app.add_flag("--other");
177 174 ASSERT_NO_THROW(cat->excludes("--other"));
178   - EXPECT_THROW(cat->excludes("--other"),CLI::OptionAlreadyAdded);
  175 + EXPECT_THROW(cat->excludes("--other"), CLI::OptionAlreadyAdded);
179 176 }
180 177  
181 178 TEST_F(TApp, CheckName) {
... ... @@ -186,7 +183,7 @@ TEST_F(TApp, CheckName) {
186 183 int x, y;
187 184 auto pos1 = app.add_option("pos1", x);
188 185 auto pos2 = app.add_option("pOs2", y);
189   -
  186 +
190 187 EXPECT_TRUE(long1->check_name("--long1"));
191 188 EXPECT_FALSE(long1->check_name("--lonG1"));
192 189  
... ...
tests/HelpTest.cpp
... ... @@ -20,7 +20,6 @@ TEST(THelp, Basic) {
20 20 EXPECT_THAT(help, HasSubstr("-h,--help"));
21 21 EXPECT_THAT(help, HasSubstr("Options:"));
22 22 EXPECT_THAT(help, HasSubstr("Usage:"));
23   -
24 23 }
25 24  
26 25 TEST(THelp, OptionalPositional) {
... ... @@ -44,11 +43,9 @@ TEST(THelp, Hidden) {
44 43 CLI::App app{"My prog"};
45 44  
46 45 std::string x;
47   - app.add_option("something", x, "My option here")
48   - ->group("Hidden");
  46 + app.add_option("something", x, "My option here")->group("Hidden");
49 47 std::string y;
50   - app.add_option("--another", y)
51   - ->group("Hidden");
  48 + app.add_option("--another", y)->group("Hidden");
52 49  
53 50 std::string help = app.help();
54 51  
... ... @@ -73,7 +70,6 @@ TEST(THelp, OptionalPositionalAndOptions) {
73 70 EXPECT_THAT(help, HasSubstr("-h,--help"));
74 71 EXPECT_THAT(help, HasSubstr("Options:"));
75 72 EXPECT_THAT(help, HasSubstr("Usage: program [OPTIONS] [something]"));
76   -
77 73 }
78 74  
79 75 TEST(THelp, RequiredPositionalAndOptions) {
... ... @@ -81,8 +77,7 @@ TEST(THelp, RequiredPositionalAndOptions) {
81 77 app.add_flag("-q,--quick");
82 78  
83 79 std::string x;
84   - app.add_option("something", x, "My option here")
85   - ->required();
  80 + app.add_option("something", x, "My option here")->required();
86 81  
87 82 std::string help = app.help();
88 83  
... ... @@ -93,7 +88,6 @@ TEST(THelp, RequiredPositionalAndOptions) {
93 88 EXPECT_THAT(help, HasSubstr("Usage: program [OPTIONS] something"));
94 89 }
95 90  
96   -
97 91 TEST(THelp, MultiOpts) {
98 92 CLI::App app{"My prog"};
99 93 std::vector<int> x, y;
... ... @@ -111,7 +105,7 @@ TEST(THelp, MultiOpts) {
111 105  
112 106 TEST(THelp, VectorOpts) {
113 107 CLI::App app{"My prog"};
114   - std::vector<int> x = {1,2};
  108 + std::vector<int> x = {1, 2};
115 109 app.add_option("-q,--quick", x, "", true);
116 110  
117 111 std::string help = app.help();
... ... @@ -136,8 +130,6 @@ TEST(THelp, MultiPosOpts) {
136 130 EXPECT_THAT(help, HasSubstr("[vals...]"));
137 131 }
138 132  
139   -
140   -
141 133 TEST(THelp, EnvName) {
142 134 CLI::App app{"My prog"};
143 135 std::string input;
... ... @@ -151,7 +143,7 @@ TEST(THelp, EnvName) {
151 143 TEST(THelp, Requires) {
152 144 CLI::App app{"My prog"};
153 145  
154   - CLI::Option* op1 = app.add_flag("--op1");
  146 + CLI::Option *op1 = app.add_flag("--op1");
155 147 app.add_flag("--op2")->requires(op1);
156 148  
157 149 std::string help = app.help();
... ... @@ -162,9 +154,9 @@ TEST(THelp, Requires) {
162 154 TEST(THelp, RequiresPositional) {
163 155 CLI::App app{"My prog"};
164 156  
165   - int x,y;
  157 + int x, y;
166 158  
167   - CLI::Option* op1 = app.add_option("op1", x, "one");
  159 + CLI::Option *op1 = app.add_option("op1", x, "one");
168 160 app.add_option("op2", y, "two")->requires(op1);
169 161  
170 162 std::string help = app.help();
... ... @@ -176,7 +168,7 @@ TEST(THelp, RequiresPositional) {
176 168 TEST(THelp, Excludes) {
177 169 CLI::App app{"My prog"};
178 170  
179   - CLI::Option* op1 = app.add_flag("--op1");
  171 + CLI::Option *op1 = app.add_flag("--op1");
180 172 app.add_flag("--op2")->excludes(op1);
181 173  
182 174 std::string help = app.help();
... ... @@ -187,9 +179,9 @@ TEST(THelp, Excludes) {
187 179 TEST(THelp, ExcludesPositional) {
188 180 CLI::App app{"My prog"};
189 181  
190   - int x,y;
  182 + int x, y;
191 183  
192   - CLI::Option* op1 = app.add_option("op1", x);
  184 + CLI::Option *op1 = app.add_option("op1", x);
193 185 app.add_option("op2", y)->excludes(op1);
194 186  
195 187 std::string help = app.help();
... ... @@ -211,15 +203,15 @@ TEST(THelp, Subcom) {
211 203  
212 204 help = app.help();
213 205 EXPECT_THAT(help, HasSubstr("Usage: program [OPTIONS] SUBCOMMAND"));
214   -
  206 +
215 207 help = sub1->help();
216 208 EXPECT_THAT(help, HasSubstr("Usage: sub1"));
217 209  
218   - char x[] = "./myprogram";
  210 + char x[] = "./myprogram";
219 211 char y[] = "sub2";
220 212  
221   - std::vector<char*> args = {x,y};
222   - app.parse((int) args.size(), args.data());
  213 + std::vector<char *> args = {x, y};
  214 + app.parse((int)args.size(), args.data());
223 215  
224 216 help = app.help();
225 217 EXPECT_THAT(help, HasSubstr("Usage: ./myprogram sub2"));
... ... @@ -229,8 +221,8 @@ TEST(THelp, IntDefaults) {
229 221 CLI::App app{"My prog"};
230 222  
231 223 int one{1}, two{2};
232   - app.add_option("--one", one, "Help for one", true);
233   - app.add_set("--set", two, {2,3,4}, "Help for set", true);
  224 + app.add_option("--one", one, "Help for one", true);
  225 + app.add_set("--set", two, {2, 3, 4}, "Help for set", true);
234 226  
235 227 std::string help = app.help();
236 228  
... ... @@ -239,14 +231,13 @@ TEST(THelp, IntDefaults) {
239 231 EXPECT_THAT(help, HasSubstr("1"));
240 232 EXPECT_THAT(help, HasSubstr("=2"));
241 233 EXPECT_THAT(help, HasSubstr("2,3,4"));
242   -
243 234 }
244 235  
245 236 TEST(THelp, SetLower) {
246 237 CLI::App app{"My prog"};
247 238  
248 239 std::string def{"One"};
249   - app.add_set_ignore_case("--set",def, {"oNe", "twO", "THREE"}, "Help for set", true);
  240 + app.add_set_ignore_case("--set", def, {"oNe", "twO", "THREE"}, "Help for set", true);
250 241  
251 242 std::string help = app.help();
252 243  
... ... @@ -255,16 +246,15 @@ TEST(THelp, SetLower) {
255 246 EXPECT_THAT(help, HasSubstr("oNe"));
256 247 EXPECT_THAT(help, HasSubstr("twO"));
257 248 EXPECT_THAT(help, HasSubstr("THREE"));
258   -
259 249 }
260 250  
261 251 TEST(Exit, ErrorWithHelp) {
262 252 CLI::App app{"My prog"};
263 253  
264   - std::vector<std::string> input {"-h"};
  254 + std::vector<std::string> input{"-h"};
265 255 try {
266 256 app.parse(input);
267   - } catch (const CLI::CallForHelp &e) {
  257 + } catch(const CLI::CallForHelp &e) {
268 258 EXPECT_EQ(static_cast<int>(CLI::ExitCodes::Success), e.get_exit_code());
269 259 }
270 260 }
... ... @@ -272,10 +262,10 @@ TEST(Exit, ErrorWithHelp) {
272 262 TEST(Exit, ErrorWithoutHelp) {
273 263 CLI::App app{"My prog"};
274 264  
275   - std::vector<std::string> input {"--none"};
  265 + std::vector<std::string> input{"--none"};
276 266 try {
277 267 app.parse(input);
278   - } catch (const CLI::ParseError &e) {
  268 + } catch(const CLI::ParseError &e) {
279 269 EXPECT_EQ(static_cast<int>(CLI::ExitCodes::Extras), e.get_exit_code());
280 270 }
281 271 }
... ... @@ -287,5 +277,4 @@ TEST(Exit, ExitCodes) {
287 277 EXPECT_EQ(0, app.exit(CLI::Success()));
288 278 EXPECT_EQ(0, app.exit(CLI::CallForHelp()));
289 279 EXPECT_EQ(i, app.exit(CLI::ExtrasError("Thing")));
290   -
291 280 }
... ...
tests/HelpersTest.cpp
... ... @@ -7,7 +7,7 @@
7 7  
8 8 TEST(Split, SimpleByToken) {
9 9 auto out = CLI::detail::split("one.two.three", '.');
10   - ASSERT_EQ((size_t) 3, out.size());
  10 + ASSERT_EQ((size_t)3, out.size());
11 11 EXPECT_EQ("one", out.at(0));
12 12 EXPECT_EQ("two", out.at(1));
13 13 EXPECT_EQ("three", out.at(2));
... ... @@ -15,13 +15,13 @@ TEST(Split, SimpleByToken) {
15 15  
16 16 TEST(Split, Single) {
17 17 auto out = CLI::detail::split("one", '.');
18   - ASSERT_EQ((size_t) 1, out.size());
  18 + ASSERT_EQ((size_t)1, out.size());
19 19 EXPECT_EQ("one", out.at(0));
20 20 }
21 21  
22 22 TEST(Split, Empty) {
23 23 auto out = CLI::detail::split("", '.');
24   - ASSERT_EQ((size_t) 1, out.size());
  24 + ASSERT_EQ((size_t)1, out.size());
25 25 EXPECT_EQ("", out.at(0));
26 26 }
27 27  
... ... @@ -38,7 +38,7 @@ TEST(Trim, Various) {
38 38 std::string a1{"sdlfkj sdflk sd s"};
39 39 CLI::detail::trim(s1);
40 40 EXPECT_EQ(a1, s1);
41   -
  41 +
42 42 std::string s2{" a \t"};
43 43 CLI::detail::trim(s2);
44 44 EXPECT_EQ("a", s2);
... ... @@ -51,13 +51,12 @@ TEST(Trim, Various) {
51 51 EXPECT_EQ("a b", CLI::detail::trim(s4));
52 52 }
53 53  
54   -
55 54 TEST(Trim, VariousFilters) {
56 55 std::string s1{" sdlfkj sdflk sd s "};
57 56 std::string a1{"sdlfkj sdflk sd s"};
58 57 CLI::detail::trim(s1, " ");
59 58 EXPECT_EQ(a1, s1);
60   -
  59 +
61 60 std::string s2{" a \t"};
62 61 CLI::detail::trim(s2, " ");
63 62 EXPECT_EQ("a \t", s2);
... ... @@ -84,10 +83,8 @@ TEST(Trim, TrimCopy) {
84 83 EXPECT_NE(orig, trimmed);
85 84 CLI::detail::trim(orig, "ab");
86 85 EXPECT_EQ(trimmed, orig);
87   -
88 86 }
89 87  
90   -
91 88 TEST(Validators, FileExists) {
92 89 std::string myfile{"TestFileNotUsed.txt"};
93 90 EXPECT_FALSE(CLI::ExistingFile(myfile));
... ... @@ -140,14 +137,14 @@ TEST(Validators, DirectoryIsFile) {
140 137 TEST(AppHelper, TempfileCreated) {
141 138 std::string name = "TestFileNotUsed.txt";
142 139 {
143   - TempFile myfile{name};
  140 + TempFile myfile{name};
144 141  
145   - EXPECT_FALSE(CLI::ExistingFile(myfile));
146   -
147   - bool ok = static_cast<bool>(std::ofstream(myfile.c_str()).put('a')); // create file
148   - EXPECT_TRUE(ok);
149   - EXPECT_TRUE(CLI::ExistingFile(name));
150   - EXPECT_THROW({TempFile otherfile(name);}, std::runtime_error);
  142 + EXPECT_FALSE(CLI::ExistingFile(myfile));
  143 +
  144 + bool ok = static_cast<bool>(std::ofstream(myfile.c_str()).put('a')); // create file
  145 + EXPECT_TRUE(ok);
  146 + EXPECT_TRUE(CLI::ExistingFile(name));
  147 + EXPECT_THROW({ TempFile otherfile(name); }, std::runtime_error);
151 148 }
152 149 EXPECT_FALSE(CLI::ExistingFile(name));
153 150 }
... ... @@ -155,9 +152,9 @@ TEST(AppHelper, TempfileCreated) {
155 152 TEST(AppHelper, TempfileNotCreated) {
156 153 std::string name = "TestFileNotUsed.txt";
157 154 {
158   - TempFile myfile{name};
  155 + TempFile myfile{name};
159 156  
160   - EXPECT_FALSE(CLI::ExistingFile(myfile));
  157 + EXPECT_FALSE(CLI::ExistingFile(myfile));
161 158 }
162 159 EXPECT_FALSE(CLI::ExistingFile(name));
163 160 }
... ... @@ -166,22 +163,21 @@ TEST(AppHelper, Ofstream) {
166 163  
167 164 std::string name = "TestFileNotUsed.txt";
168 165 {
169   - TempFile myfile(name);
  166 + TempFile myfile(name);
170 167  
171   - {
172   - std::ofstream out{myfile};
173   - out << "this is output" << std::endl;
174   - }
  168 + {
  169 + std::ofstream out{myfile};
  170 + out << "this is output" << std::endl;
  171 + }
175 172  
176   - EXPECT_TRUE(CLI::ExistingFile(myfile));
  173 + EXPECT_TRUE(CLI::ExistingFile(myfile));
177 174 }
178 175 EXPECT_FALSE(CLI::ExistingFile(name));
179   -
180 176 }
181 177  
182 178 TEST(Split, StringList) {
183 179  
184   - std::vector<std::string> results {"a", "long", "--lone", "-q"};
  180 + std::vector<std::string> results{"a", "long", "--lone", "-q"};
185 181 EXPECT_EQ(results, CLI::detail::split_names("a,long,--lone,-q"));
186 182  
187 183 EXPECT_EQ(std::vector<std::string>({"one"}), CLI::detail::split_names("one"));
... ... @@ -232,7 +228,6 @@ TEST(RegEx, Longs) {
232 228 EXPECT_FALSE(CLI::detail::split_long("-things", name, value));
233 229 EXPECT_FALSE(CLI::detail::split_long("Q", name, value));
234 230 EXPECT_FALSE(CLI::detail::split_long("--", name, value));
235   -
236 231 }
237 232  
238 233 TEST(RegEx, SplittingNew) {
... ... @@ -246,7 +241,8 @@ TEST(RegEx, SplittingNew) {
246 241 EXPECT_EQ(std::vector<std::string>({"s", "q"}), shorts);
247 242 EXPECT_EQ("", pname);
248 243  
249   - EXPECT_NO_THROW(std::tie(shorts, longs, pname) = CLI::detail::get_names({"--long", "", "-s", "-q", "", "--also-long"}));
  244 + EXPECT_NO_THROW(std::tie(shorts, longs, pname) =
  245 + CLI::detail::get_names({"--long", "", "-s", "-q", "", "--also-long"}));
250 246 EXPECT_EQ(std::vector<std::string>({"long", "also-long"}), longs);
251 247 EXPECT_EQ(std::vector<std::string>({"s", "q"}), shorts);
252 248  
... ... @@ -254,57 +250,52 @@ TEST(RegEx, SplittingNew) {
254 250 EXPECT_THROW(std::tie(shorts, longs, pname) = CLI::detail::get_names({"--"}), CLI::BadNameString);
255 251 EXPECT_THROW(std::tie(shorts, longs, pname) = CLI::detail::get_names({"-hi"}), CLI::BadNameString);
256 252 EXPECT_THROW(std::tie(shorts, longs, pname) = CLI::detail::get_names({"---hi"}), CLI::BadNameString);
257   - EXPECT_THROW(std::tie(shorts, longs, pname) = CLI::detail::get_names({"one","two"}), CLI::BadNameString);
258   -
  253 + EXPECT_THROW(std::tie(shorts, longs, pname) = CLI::detail::get_names({"one", "two"}), CLI::BadNameString);
259 254 }
260 255  
261   -TEST(String, ToLower) {
262   -
263   - EXPECT_EQ("one and two", CLI::detail::to_lower("one And TWO"));
264   -}
  256 +TEST(String, ToLower) { EXPECT_EQ("one and two", CLI::detail::to_lower("one And TWO")); }
265 257  
266 258 TEST(Join, Forward) {
267   - std::vector<std::string> val {{"one", "two", "three"}};
  259 + std::vector<std::string> val{{"one", "two", "three"}};
268 260 EXPECT_EQ("one,two,three", CLI::detail::join(val));
269 261 EXPECT_EQ("one;two;three", CLI::detail::join(val, ";"));
270 262 }
271 263  
272   -
273 264 TEST(Join, Backward) {
274   - std::vector<std::string> val {{"three", "two", "one"}};
  265 + std::vector<std::string> val{{"three", "two", "one"}};
275 266 EXPECT_EQ("one,two,three", CLI::detail::rjoin(val));
276 267 EXPECT_EQ("one;two;three", CLI::detail::rjoin(val, ";"));
277 268 }
278 269  
279 270 TEST(SplitUp, Simple) {
280 271 std::vector<std::string> oput = {"one", "two three"};
281   - std::string orig {R"(one "two three")"};
  272 + std::string orig{R"(one "two three")"};
282 273 std::vector<std::string> result = CLI::detail::split_up(orig);
283 274 EXPECT_EQ(oput, result);
284 275 }
285 276  
286 277 TEST(SplitUp, Layered) {
287 278 std::vector<std::string> output = {R"(one 'two three')"};
288   - std::string orig {R"("one 'two three'")"};
  279 + std::string orig{R"("one 'two three'")"};
289 280 std::vector<std::string> result = CLI::detail::split_up(orig);
290 281 EXPECT_EQ(output, result);
291 282 }
292 283  
293 284 TEST(SplitUp, Spaces) {
294 285 std::vector<std::string> oput = {"one", " two three"};
295   - std::string orig {R"( one " two three" )"};
  286 + std::string orig{R"( one " two three" )"};
296 287 std::vector<std::string> result = CLI::detail::split_up(orig);
297 288 EXPECT_EQ(oput, result);
298 289 }
299 290  
300 291 TEST(SplitUp, BadStrings) {
301 292 std::vector<std::string> oput = {"one", " two three"};
302   - std::string orig {R"( one " two three )"};
  293 + std::string orig{R"( one " two three )"};
303 294 std::vector<std::string> result = CLI::detail::split_up(orig);
304 295 EXPECT_EQ(oput, result);
305 296  
306 297 oput = {"one", " two three"};
307   - orig = R"( one ' two three )";
  298 + orig = R"( one ' two three )";
308 299 result = CLI::detail::split_up(orig);
309 300 EXPECT_EQ(oput, result);
310 301 }
... ... @@ -327,8 +318,8 @@ TEST(Types, TypeName) {
327 318  
328 319 std::string text_name = CLI::detail::type_name<std::string>();
329 320 EXPECT_EQ("TEXT", text_name);
330   -
331   - std::string text2_name = CLI::detail::type_name<char*>();
  321 +
  322 + std::string text2_name = CLI::detail::type_name<char *>();
332 323 EXPECT_EQ("TEXT", text2_name);
333 324 }
334 325  
... ... @@ -350,11 +341,11 @@ TEST(Types, LexicalCastDouble) {
350 341 std::string input = "9.12";
351 342 long double x;
352 343 EXPECT_TRUE(CLI::detail::lexical_cast(input, x));
353   - EXPECT_FLOAT_EQ((float) 9.12, (float) x);
  344 + EXPECT_FLOAT_EQ((float)9.12, (float)x);
354 345  
355 346 std::string bad_input = "hello";
356 347 EXPECT_FALSE(CLI::detail::lexical_cast(bad_input, x));
357   -
  348 +
358 349 std::string overflow_input = "1" + std::to_string(LDBL_MAX);
359 350 EXPECT_FALSE(CLI::detail::lexical_cast(overflow_input, x));
360 351 }
... ... @@ -365,4 +356,3 @@ TEST(Types, LexicalCastString) {
365 356 CLI::detail::lexical_cast(input, output);
366 357 EXPECT_EQ(input, output);
367 358 }
368   -
... ...
tests/IniTest.cpp
... ... @@ -3,7 +3,7 @@
3 3 #include <cstdio>
4 4 #include <sstream>
5 5 #include "gmock/gmock.h"
6   -
  6 +
7 7 using ::testing::HasSubstr;
8 8 using ::testing::Not;
9 9  
... ... @@ -17,14 +17,13 @@ TEST(StringBased, First) {
17 17  
18 18 std::vector<CLI::detail::ini_ret_t> output = CLI::detail::parse_ini(ofile);
19 19  
20   - EXPECT_EQ((size_t) 2, output.size());
  20 + EXPECT_EQ((size_t)2, output.size());
21 21 EXPECT_EQ("one", output.at(0).name());
22   - EXPECT_EQ((size_t) 1, output.at(0).inputs.size());
  22 + EXPECT_EQ((size_t)1, output.at(0).inputs.size());
23 23 EXPECT_EQ("three", output.at(0).inputs.at(0));
24 24 EXPECT_EQ("two", output.at(1).name());
25   - EXPECT_EQ((size_t) 1, output.at(1).inputs.size());
  25 + EXPECT_EQ((size_t)1, output.at(1).inputs.size());
26 26 EXPECT_EQ("four", output.at(1).inputs.at(0));
27   -
28 27 }
29 28  
30 29 TEST(StringBased, FirstWithComments) {
... ... @@ -39,12 +38,12 @@ TEST(StringBased, FirstWithComments) {
39 38  
40 39 auto output = CLI::detail::parse_ini(ofile);
41 40  
42   - EXPECT_EQ((size_t) 2, output.size());
  41 + EXPECT_EQ((size_t)2, output.size());
43 42 EXPECT_EQ("one", output.at(0).name());
44   - EXPECT_EQ((size_t) 1, output.at(0).inputs.size());
  43 + EXPECT_EQ((size_t)1, output.at(0).inputs.size());
45 44 EXPECT_EQ("three", output.at(0).inputs.at(0));
46 45 EXPECT_EQ("two", output.at(1).name());
47   - EXPECT_EQ((size_t) 1, output.at(1).inputs.size());
  46 + EXPECT_EQ((size_t)1, output.at(1).inputs.size());
48 47 EXPECT_EQ("four", output.at(1).inputs.at(0));
49 48 }
50 49  
... ... @@ -59,15 +58,15 @@ TEST(StringBased, Quotes) {
59 58  
60 59 auto output = CLI::detail::parse_ini(ofile);
61 60  
62   - EXPECT_EQ((size_t) 3, output.size());
  61 + EXPECT_EQ((size_t)3, output.size());
63 62 EXPECT_EQ("one", output.at(0).name());
64   - EXPECT_EQ((size_t) 1, output.at(0).inputs.size());
  63 + EXPECT_EQ((size_t)1, output.at(0).inputs.size());
65 64 EXPECT_EQ("three", output.at(0).inputs.at(0));
66 65 EXPECT_EQ("two", output.at(1).name());
67   - EXPECT_EQ((size_t) 1, output.at(1).inputs.size());
  66 + EXPECT_EQ((size_t)1, output.at(1).inputs.size());
68 67 EXPECT_EQ("four", output.at(1).inputs.at(0));
69 68 EXPECT_EQ("five", output.at(2).name());
70   - EXPECT_EQ((size_t) 1, output.at(2).inputs.size());
  69 + EXPECT_EQ((size_t)1, output.at(2).inputs.size());
71 70 EXPECT_EQ("six and seven", output.at(2).inputs.at(0));
72 71 }
73 72  
... ... @@ -82,21 +81,20 @@ TEST(StringBased, Vector) {
82 81  
83 82 auto output = CLI::detail::parse_ini(ofile);
84 83  
85   - EXPECT_EQ((size_t) 3, output.size());
  84 + EXPECT_EQ((size_t)3, output.size());
86 85 EXPECT_EQ("one", output.at(0).name());
87   - EXPECT_EQ((size_t) 1, output.at(0).inputs.size());
  86 + EXPECT_EQ((size_t)1, output.at(0).inputs.size());
88 87 EXPECT_EQ("three", output.at(0).inputs.at(0));
89 88 EXPECT_EQ("two", output.at(1).name());
90   - EXPECT_EQ((size_t) 1, output.at(1).inputs.size());
  89 + EXPECT_EQ((size_t)1, output.at(1).inputs.size());
91 90 EXPECT_EQ("four", output.at(1).inputs.at(0));
92 91 EXPECT_EQ("five", output.at(2).name());
93   - EXPECT_EQ((size_t) 3, output.at(2).inputs.size());
  92 + EXPECT_EQ((size_t)3, output.at(2).inputs.size());
94 93 EXPECT_EQ("six", output.at(2).inputs.at(0));
95 94 EXPECT_EQ("and", output.at(2).inputs.at(1));
96 95 EXPECT_EQ("seven", output.at(2).inputs.at(2));
97 96 }
98 97  
99   -
100 98 TEST(StringBased, Spaces) {
101 99 std::stringstream ofile;
102 100  
... ... @@ -107,12 +105,12 @@ TEST(StringBased, Spaces) {
107 105  
108 106 auto output = CLI::detail::parse_ini(ofile);
109 107  
110   - EXPECT_EQ((size_t) 2, output.size());
  108 + EXPECT_EQ((size_t)2, output.size());
111 109 EXPECT_EQ("one", output.at(0).name());
112   - EXPECT_EQ((size_t) 1, output.at(0).inputs.size());
  110 + EXPECT_EQ((size_t)1, output.at(0).inputs.size());
113 111 EXPECT_EQ("three", output.at(0).inputs.at(0));
114 112 EXPECT_EQ("two", output.at(1).name());
115   - EXPECT_EQ((size_t) 1, output.at(1).inputs.size());
  113 + EXPECT_EQ((size_t)1, output.at(1).inputs.size());
116 114 EXPECT_EQ("four", output.at(1).inputs.at(0));
117 115 }
118 116  
... ... @@ -126,18 +124,17 @@ TEST(StringBased, Sections) {
126 124 ofile.seekg(0, std::ios::beg);
127 125  
128 126 auto output = CLI::detail::parse_ini(ofile);
129   -
130   - EXPECT_EQ((size_t) 2, output.size());
  127 +
  128 + EXPECT_EQ((size_t)2, output.size());
131 129 EXPECT_EQ("one", output.at(0).name());
132   - EXPECT_EQ((size_t) 1, output.at(0).inputs.size());
  130 + EXPECT_EQ((size_t)1, output.at(0).inputs.size());
133 131 EXPECT_EQ("three", output.at(0).inputs.at(0));
134 132 EXPECT_EQ("two", output.at(1).name());
135 133 EXPECT_EQ("second", output.at(1).parent());
136   - EXPECT_EQ((size_t) 1, output.at(1).inputs.size());
  134 + EXPECT_EQ((size_t)1, output.at(1).inputs.size());
137 135 EXPECT_EQ("four", output.at(1).inputs.at(0));
138 136 }
139 137  
140   -
141 138 TEST(StringBased, SpacesSections) {
142 139 std::stringstream ofile;
143 140  
... ... @@ -151,13 +148,13 @@ TEST(StringBased, SpacesSections) {
151 148  
152 149 auto output = CLI::detail::parse_ini(ofile);
153 150  
154   - EXPECT_EQ((size_t) 2, output.size());
  151 + EXPECT_EQ((size_t)2, output.size());
155 152 EXPECT_EQ("one", output.at(0).name());
156   - EXPECT_EQ((size_t) 1, output.at(0).inputs.size());
  153 + EXPECT_EQ((size_t)1, output.at(0).inputs.size());
157 154 EXPECT_EQ("three", output.at(0).inputs.at(0));
158 155 EXPECT_EQ("two", output.at(1).name());
159 156 EXPECT_EQ("second", output.at(1).parent());
160   - EXPECT_EQ((size_t) 1, output.at(1).inputs.size());
  157 + EXPECT_EQ((size_t)1, output.at(1).inputs.size());
161 158 EXPECT_EQ("four", output.at(1).inputs.at(0));
162 159 }
163 160  
... ... @@ -174,7 +171,7 @@ TEST_F(TApp, IniNotRequired) {
174 171 out << "three=3" << std::endl;
175 172 }
176 173  
177   - int one=0, two=0, three=0;
  174 + int one = 0, two = 0, three = 0;
178 175 app.add_option("--one", one);
179 176 app.add_option("--two", two);
180 177 app.add_option("--three", three);
... ... @@ -188,7 +185,7 @@ TEST_F(TApp, IniNotRequired) {
188 185 EXPECT_EQ(3, three);
189 186  
190 187 app.reset();
191   - one=two=three=0;
  188 + one = two = three = 0;
192 189 args = {"--one=1", "--two=2"};
193 190  
194 191 run();
... ... @@ -196,7 +193,6 @@ TEST_F(TApp, IniNotRequired) {
196 193 EXPECT_EQ(1, one);
197 194 EXPECT_EQ(2, two);
198 195 EXPECT_EQ(3, three);
199   -
200 196 }
201 197  
202 198 TEST_F(TApp, IniRequiredNotFound) {
... ... @@ -205,7 +201,6 @@ TEST_F(TApp, IniRequiredNotFound) {
205 201 app.add_config("--config", noini, "", true);
206 202  
207 203 EXPECT_THROW(run(), CLI::FileError);
208   -
209 204 }
210 205  
211 206 TEST_F(TApp, IniOverwrite) {
... ... @@ -224,7 +219,7 @@ TEST_F(TApp, IniOverwrite) {
224 219 app.add_config("--conf", next);
225 220 int two = 7;
226 221 app.add_option("--two", two);
227   -
  222 +
228 223 run();
229 224  
230 225 EXPECT_EQ(99, two);
... ... @@ -243,7 +238,7 @@ TEST_F(TApp, IniRequired) {
243 238 out << "three=3" << std::endl;
244 239 }
245 240  
246   - int one=0, two=0, three=0;
  241 + int one = 0, two = 0, three = 0;
247 242 app.add_option("--one", one)->required();
248 243 app.add_option("--two", two)->required();
249 244 app.add_option("--three", three)->required();
... ... @@ -253,7 +248,7 @@ TEST_F(TApp, IniRequired) {
253 248 run();
254 249  
255 250 app.reset();
256   - one=two=three=0;
  251 + one = two = three = 0;
257 252 args = {"--one=1", "--two=2"};
258 253  
259 254 run();
... ... @@ -267,7 +262,6 @@ TEST_F(TApp, IniRequired) {
267 262 args = {"--two=2"};
268 263  
269 264 EXPECT_THROW(run(), CLI::RequiredError);
270   -
271 265 }
272 266  
273 267 TEST_F(TApp, IniVector) {
... ... @@ -289,12 +283,10 @@ TEST_F(TApp, IniVector) {
289 283  
290 284 run();
291 285  
292   - EXPECT_EQ(std::vector<int>({2,3}), two);
293   - EXPECT_EQ(std::vector<int>({1,2,3}), three);
294   -
  286 + EXPECT_EQ(std::vector<int>({2, 3}), two);
  287 + EXPECT_EQ(std::vector<int>({1, 2, 3}), three);
295 288 }
296 289  
297   -
298 290 TEST_F(TApp, IniLayered) {
299 291  
300 292 TempFile tmpini{"TestIniTmp.ini"};
... ... @@ -310,7 +302,7 @@ TEST_F(TApp, IniLayered) {
310 302 out << "subsubcom.val=3" << std::endl;
311 303 }
312 304  
313   - int one=0, two=0, three=0;
  305 + int one = 0, two = 0, three = 0;
314 306 app.add_option("--val", one);
315 307 auto subcom = app.add_subcommand("subcom");
316 308 subcom->add_option("--val", two);
... ... @@ -322,12 +314,11 @@ TEST_F(TApp, IniLayered) {
322 314 EXPECT_EQ(1, one);
323 315 EXPECT_EQ(2, two);
324 316 EXPECT_EQ(3, three);
325   -
326 317 }
327 318  
328 319 TEST_F(TApp, IniFailure) {
329 320  
330   - TempFile tmpini{"TestIniTmp.ini"};
  321 + TempFile tmpini{"TestIniTmp.ini"};
331 322  
332 323 app.add_config("--config", tmpini);
333 324  
... ... @@ -340,7 +331,6 @@ TEST_F(TApp, IniFailure) {
340 331 EXPECT_THROW(run(), CLI::ExtrasINIError);
341 332 }
342 333  
343   -
344 334 TEST_F(TApp, IniSubFailure) {
345 335  
346 336 TempFile tmpini{"TestIniTmp.ini"};
... ... @@ -357,7 +347,6 @@ TEST_F(TApp, IniSubFailure) {
357 347 EXPECT_THROW(run(), CLI::ExtrasINIError);
358 348 }
359 349  
360   -
361 350 TEST_F(TApp, IniNoSubFailure) {
362 351  
363 352 TempFile tmpini{"TestIniTmp.ini"};
... ... @@ -388,7 +377,6 @@ TEST_F(TApp, IniFlagConvertFailure) {
388 377 EXPECT_THROW(run(), CLI::ConversionError);
389 378 }
390 379  
391   -
392 380 TEST_F(TApp, IniFlagNumbers) {
393 381  
394 382 TempFile tmpini{"TestIniTmp.ini"};
... ... @@ -474,7 +462,6 @@ TEST_F(TApp, IniFlags) {
474 462 EXPECT_EQ(true, three);
475 463 EXPECT_EQ(true, four);
476 464 EXPECT_EQ(true, five);
477   -
478 465 }
479 466  
480 467 TEST_F(TApp, IniOutputSimple) {
... ... @@ -528,7 +515,7 @@ TEST_F(TApp, IniOutputFlag) {
528 515 TEST_F(TApp, IniOutputSet) {
529 516  
530 517 int v;
531   - app.add_set("--simple", v, {1,2,3});
  518 + app.add_set("--simple", v, {1, 2, 3});
532 519  
533 520 args = {"--simple=2"};
534 521  
... ... @@ -538,10 +525,9 @@ TEST_F(TApp, IniOutputSet) {
538 525 EXPECT_THAT(str, HasSubstr("simple=2"));
539 526 }
540 527  
541   -
542 528 TEST_F(TApp, IniOutputDefault) {
543 529  
544   - int v=7;
  530 + int v = 7;
545 531 app.add_option("--simple", v, "", true);
546 532  
547 533 run();
... ... @@ -574,7 +560,7 @@ TEST_F(TApp, IniQuotedOutput) {
574 560  
575 561 std::string val2;
576 562 app.add_option("--val2", val2);
577   -
  563 +
578 564 args = {"--val1", "I am a string", "--val2", R"(I am a "confusing" string)"};
579 565  
580 566 run();
... ... @@ -585,5 +571,4 @@ TEST_F(TApp, IniQuotedOutput) {
585 571 std::string str = app.config_to_str();
586 572 EXPECT_THAT(str, HasSubstr("val1=\"I am a string\""));
587 573 EXPECT_THAT(str, HasSubstr("val2='I am a \"confusing\" string'"));
588   -
589 574 }
... ...
tests/NewParseTest.cpp
... ... @@ -6,21 +6,19 @@ using ::testing::HasSubstr;
6 6  
7 7 using cx = std::complex<double>;
8 8  
9   -CLI::Option* add_option(CLI::App& app,
10   - std::string name, cx& variable,
11   - std::string description="", bool defaulted=false) {
12   - CLI::callback_t fun = [&variable](CLI::results_t res){
13   - if(res.size()!=2)
  9 +CLI::Option *
  10 +add_option(CLI::App &app, std::string name, cx &variable, std::string description = "", bool defaulted = false) {
  11 + CLI::callback_t fun = [&variable](CLI::results_t res) {
  12 + if(res.size() != 2)
14 13 return false;
15   - double x,y;
16   - bool worked = CLI::detail::lexical_cast(res[0], x)
17   - && CLI::detail::lexical_cast(res[1], y);
  14 + double x, y;
  15 + bool worked = CLI::detail::lexical_cast(res[0], x) && CLI::detail::lexical_cast(res[1], y);
18 16 if(worked)
19   - variable = cx(x,y);
  17 + variable = cx(x, y);
20 18 return worked;
21 19 };
22 20  
23   - CLI::Option* opt = app.add_option(name, fun, description, defaulted);
  21 + CLI::Option *opt = app.add_option(name, fun, description, defaulted);
24 22 opt->set_custom_option("COMPLEX", 2);
25 23 if(defaulted) {
26 24 std::stringstream out;
... ... @@ -32,19 +30,18 @@ CLI::Option* add_option(CLI::App&amp; app,
32 30  
33 31 TEST_F(TApp, AddingComplexParser) {
34 32  
35   -
36   - cx comp {0, 0};
  33 + cx comp{0, 0};
37 34 add_option(app, "-c,--complex", comp);
38 35 args = {"-c", "1.5", "2.5"};
39 36  
40 37 run();
41 38  
42   - EXPECT_EQ(cx(1.5,2.5), comp);
  39 + EXPECT_EQ(cx(1.5, 2.5), comp);
43 40 }
44 41  
45 42 TEST_F(TApp, DefaultComplex) {
46 43  
47   - cx comp {1, 2};
  44 + cx comp{1, 2};
48 45 add_option(app, "-c,--complex", comp, "", true);
49 46 args = {"-c", "4", "3"};
50 47  
... ... @@ -52,15 +49,15 @@ TEST_F(TApp, DefaultComplex) {
52 49 EXPECT_THAT(help, HasSubstr("1"));
53 50 EXPECT_THAT(help, HasSubstr("2"));
54 51  
55   - EXPECT_EQ(cx(1,2), comp);
  52 + EXPECT_EQ(cx(1, 2), comp);
56 53  
57 54 run();
58 55  
59   - EXPECT_EQ(cx(4,3), comp);
  56 + EXPECT_EQ(cx(4, 3), comp);
60 57 }
61 58  
62 59 TEST_F(TApp, BuiltinComplex) {
63   - cx comp {1, 2};
  60 + cx comp{1, 2};
64 61 app.add_complex("-c,--complex", comp, "", true);
65 62  
66 63 args = {"-c", "4", "3"};
... ... @@ -70,28 +67,26 @@ TEST_F(TApp, BuiltinComplex) {
70 67 EXPECT_THAT(help, HasSubstr("2"));
71 68 EXPECT_THAT(help, HasSubstr("COMPLEX"));
72 69  
73   - EXPECT_EQ(cx(1,2), comp);
  70 + EXPECT_EQ(cx(1, 2), comp);
74 71  
75 72 run();
76 73  
77   - EXPECT_EQ(cx(4,3), comp);
78   -
  74 + EXPECT_EQ(cx(4, 3), comp);
79 75 }
80 76  
81   -
82 77 TEST_F(TApp, BuiltinComplexIgnoreI) {
83   - cx comp {1, 2};
  78 + cx comp{1, 2};
84 79 app.add_complex("-c,--complex", comp);
85 80  
86 81 args = {"-c", "4", "3i"};
87 82  
88 83 run();
89 84  
90   - EXPECT_EQ(cx(4,3), comp);
  85 + EXPECT_EQ(cx(4, 3), comp);
91 86 }
92 87  
93 88 TEST_F(TApp, BuiltinComplexFail) {
94   - cx comp {1, 2};
  89 + cx comp{1, 2};
95 90 app.add_complex("-c,--complex", comp);
96 91  
97 92 args = {"-c", "4"};
... ...
tests/SimpleTest.cpp
... ... @@ -11,20 +11,18 @@ using input_t = std::vector&lt;std::string&gt;;
11 11 TEST(Basic, Empty) {
12 12  
13 13 {
14   - CLI::App app;
15   - input_t simpleput;
16   - app.parse(simpleput);
  14 + CLI::App app;
  15 + input_t simpleput;
  16 + app.parse(simpleput);
17 17 }
18 18 {
19   - CLI::App app;
20   - input_t spare = {"spare"};
21   - EXPECT_THROW(app.parse(spare), CLI::ExtrasError);
  19 + CLI::App app;
  20 + input_t spare = {"spare"};
  21 + EXPECT_THROW(app.parse(spare), CLI::ExtrasError);
22 22 }
23 23 {
24   - CLI::App app;
25   - input_t simpleput;
26   - app.parse(simpleput);
  24 + CLI::App app;
  25 + input_t simpleput;
  26 + app.parse(simpleput);
27 27 }
28 28 }
29   -
30   -
... ...
tests/SubcommandTest.cpp
... ... @@ -9,15 +9,15 @@ TEST_F(TApp, BasicSubcommands) {
9 9 EXPECT_THROW(app.get_subcommand("sub3"), CLI::OptionNotFound);
10 10  
11 11 run();
12   - EXPECT_EQ((size_t) 0, app.get_subcommands().size());
13   -
  12 + EXPECT_EQ((size_t)0, app.get_subcommands().size());
  13 +
14 14 app.reset();
15 15 args = {"sub1"};
16 16 run();
17 17 EXPECT_EQ(sub1, app.get_subcommands().at(0));
18 18  
19 19 app.reset();
20   - EXPECT_EQ((size_t) 0, app.get_subcommands().size());
  20 + EXPECT_EQ((size_t)0, app.get_subcommands().size());
21 21  
22 22 args = {"sub2"};
23 23 run();
... ... @@ -34,7 +34,6 @@ TEST_F(TApp, MultiSubFallthrough) {
34 34 auto sub1 = app.add_subcommand("sub1");
35 35 auto sub2 = app.add_subcommand("sub2");
36 36  
37   -
38 37 args = {"sub1", "sub2"};
39 38 run();
40 39 EXPECT_TRUE(app.got_subcommand("sub1"));
... ... @@ -71,27 +70,21 @@ TEST_F(TApp, MultiSubFallthrough) {
71 70 EXPECT_TRUE(*sub1);
72 71 EXPECT_FALSE(*sub2);
73 72 EXPECT_FALSE(sub2->parsed());
74   -
  73 +
75 74 EXPECT_THROW(app.got_subcommand("sub3"), CLI::OptionNotFound);
76 75 }
77 76  
78   -
79 77 TEST_F(TApp, Callbacks) {
80 78 auto sub1 = app.add_subcommand("sub1");
81   - sub1->set_callback([](){
82   - throw CLI::Success();
83   - });
  79 + sub1->set_callback([]() { throw CLI::Success(); });
84 80 auto sub2 = app.add_subcommand("sub2");
85 81 bool val = false;
86   - sub2->set_callback([&val](){
87   - val = true;
88   - });
89   -
  82 + sub2->set_callback([&val]() { val = true; });
  83 +
90 84 args = {"sub2"};
91 85 EXPECT_FALSE(val);
92 86 run();
93 87 EXPECT_TRUE(val);
94   -
95 88 }
96 89  
97 90 TEST_F(TApp, NoFallThroughOpts) {
... ... @@ -99,18 +92,17 @@ TEST_F(TApp, NoFallThroughOpts) {
99 92 app.add_option("--val", val);
100 93  
101 94 app.add_subcommand("sub");
102   -
  95 +
103 96 args = {"sub", "--val", "2"};
104 97 EXPECT_THROW(run(), CLI::ExtrasError);
105 98 }
106 99  
107   -
108 100 TEST_F(TApp, NoFallThroughPositionals) {
109 101 int val = 1;
110 102 app.add_option("val", val);
111 103  
112 104 app.add_subcommand("sub");
113   -
  105 +
114 106 args = {"sub", "2"};
115 107 EXPECT_THROW(run(), CLI::ExtrasError);
116 108 }
... ... @@ -121,33 +113,31 @@ TEST_F(TApp, FallThroughRegular) {
121 113 app.add_option("--val", val);
122 114  
123 115 app.add_subcommand("sub");
124   -
  116 +
125 117 args = {"sub", "--val", "2"};
126 118 // Should not throw
127 119 run();
128 120 }
129 121  
130   -
131 122 TEST_F(TApp, FallThroughShort) {
132 123 app.fallthrough();
133 124 int val = 1;
134 125 app.add_option("-v", val);
135 126  
136 127 app.add_subcommand("sub");
137   -
  128 +
138 129 args = {"sub", "-v", "2"};
139 130 // Should not throw
140 131 run();
141 132 }
142 133  
143   -
144 134 TEST_F(TApp, FallThroughPositional) {
145 135 app.fallthrough();
146 136 int val = 1;
147 137 app.add_option("val", val);
148 138  
149 139 app.add_subcommand("sub");
150   -
  140 +
151 141 args = {"sub", "2"};
152 142 // Should not throw
153 143 run();
... ... @@ -159,13 +149,12 @@ TEST_F(TApp, FallThroughEquals) {
159 149 app.add_option("--val", val);
160 150  
161 151 app.add_subcommand("sub");
162   -
  152 +
163 153 args = {"sub", "--val=2"};
164 154 // Should not throw
165 155 run();
166 156 }
167 157  
168   -
169 158 TEST_F(TApp, EvilParseFallthrough) {
170 159 app.fallthrough();
171 160 int val1 = 0, val2 = 0;
... ... @@ -173,7 +162,7 @@ TEST_F(TApp, EvilParseFallthrough) {
173 162  
174 163 auto sub = app.add_subcommand("sub");
175 164 sub->add_option("val2", val2);
176   -
  165 +
177 166 args = {"sub", "--val1", "1", "2"};
178 167 // Should not throw
179 168 run();
... ... @@ -188,10 +177,8 @@ TEST_F(TApp, CallbackOrdering) {
188 177 app.add_option("--val", val);
189 178  
190 179 auto sub = app.add_subcommand("sub");
191   - sub->set_callback([&val, &sub_val](){
192   - sub_val = val;
193   - });
194   -
  180 + sub->set_callback([&val, &sub_val]() { sub_val = val; });
  181 +
195 182 args = {"sub", "--val=2"};
196 183 run();
197 184 EXPECT_EQ(2, val);
... ... @@ -202,7 +189,6 @@ TEST_F(TApp, CallbackOrdering) {
202 189 run();
203 190 EXPECT_EQ(2, val);
204 191 EXPECT_EQ(2, sub_val);
205   -
206 192 }
207 193  
208 194 TEST_F(TApp, RequiredSubCom) {
... ... @@ -218,7 +204,6 @@ TEST_F(TApp, RequiredSubCom) {
218 204 args = {"sub1"};
219 205  
220 206 run();
221   -
222 207 }
223 208  
224 209 TEST_F(TApp, Required1SubCom) {
... ... @@ -248,8 +233,8 @@ TEST_F(TApp, BadSubcomSearch) {
248 233  
249 234 struct SubcommandProgram : public TApp {
250 235  
251   - CLI::App* start;
252   - CLI::App* stop;
  236 + CLI::App *start;
  237 + CLI::App *stop;
253 238  
254 239 int dummy;
255 240 std::string file;
... ... @@ -258,7 +243,7 @@ struct SubcommandProgram : public TApp {
258 243 SubcommandProgram() {
259 244 start = app.add_subcommand("start", "Start prog");
260 245 stop = app.add_subcommand("stop", "Stop prog");
261   -
  246 +
262 247 app.add_flag("-d", dummy, "My dummy var");
263 248 start->add_option("-f,--file", file, "File name");
264 249 stop->add_flag("-c,--count", count, "Some flag opt");
... ... @@ -275,7 +260,6 @@ TEST_F(SubcommandProgram, Working) {
275 260 EXPECT_EQ("filename", file);
276 261 }
277 262  
278   -
279 263 TEST_F(SubcommandProgram, Spare) {
280 264 args = {"extra", "-d", "start", "-ffilename"};
281 265  
... ... @@ -292,7 +276,7 @@ TEST_F(SubcommandProgram, Multiple) {
292 276 args = {"-d", "start", "-ffilename", "stop"};
293 277  
294 278 run();
295   - EXPECT_EQ((size_t) 2, app.get_subcommands().size());
  279 + EXPECT_EQ((size_t)2, app.get_subcommands().size());
296 280 EXPECT_EQ(1, dummy);
297 281 EXPECT_EQ("filename", file);
298 282 }
... ... @@ -308,20 +292,17 @@ TEST_F(SubcommandProgram, MultipleArgs) {
308 292  
309 293 run();
310 294  
311   - EXPECT_EQ((size_t) 2, app.get_subcommands().size());
312   -
  295 + EXPECT_EQ((size_t)2, app.get_subcommands().size());
313 296 }
314 297  
315 298 TEST_F(SubcommandProgram, CaseCheck) {
316 299 args = {"Start"};
317 300 EXPECT_THROW(run(), CLI::ExtrasError);
318 301  
319   -
320 302 app.reset();
321 303 args = {"start"};
322 304 run();
323 305  
324   -
325 306 app.reset();
326 307 start->ignore_case();
327 308 run();
... ... @@ -337,15 +318,15 @@ TEST_F(TApp, SubcomInheritCaseCheck) {
337 318 auto sub2 = app.add_subcommand("sub2");
338 319  
339 320 run();
340   - EXPECT_EQ((size_t) 0, app.get_subcommands().size());
341   -
  321 + EXPECT_EQ((size_t)0, app.get_subcommands().size());
  322 +
342 323 app.reset();
343 324 args = {"SuB1"};
344 325 run();
345 326 EXPECT_EQ(sub1, app.get_subcommands().at(0));
346 327  
347 328 app.reset();
348   - EXPECT_EQ((size_t) 0, app.get_subcommands().size());
  329 + EXPECT_EQ((size_t)0, app.get_subcommands().size());
349 330  
350 331 args = {"sUb2"};
351 332 run();
... ... @@ -366,9 +347,7 @@ TEST_F(SubcommandProgram, HelpOrder) {
366 347  
367 348 TEST_F(SubcommandProgram, Callbacks) {
368 349  
369   - start->set_callback([](){
370   - throw CLI::Success();
371   - });
  350 + start->set_callback([]() { throw CLI::Success(); });
372 351  
373 352 run();
374 353  
... ... @@ -377,5 +356,4 @@ TEST_F(SubcommandProgram, Callbacks) {
377 356 args = {"start"};
378 357  
379 358 EXPECT_THROW(run(), CLI::Success);
380   -
381 359 }
... ...
tests/TimerTest.cpp
... ... @@ -28,7 +28,7 @@ TEST(Timer, STimes) {
28 28 */
29 29  
30 30 // Fails on Windows
31   -//TEST(Timer, UStimes) {
  31 +// TEST(Timer, UStimes) {
32 32 // CLI::Timer timer;
33 33 // std::this_thread::sleep_for(std::chrono::microseconds(2));
34 34 // std::string output = timer.to_string();
... ... @@ -58,8 +58,7 @@ TEST(Timer, PrintTimer) {
58 58  
59 59 TEST(Timer, TimeItTimer) {
60 60 CLI::Timer timer;
61   - std::string output = timer.time_it([](){
62   - std::this_thread::sleep_for(std::chrono::milliseconds(10));}, .1);
  61 + std::string output = timer.time_it([]() { std::this_thread::sleep_for(std::chrono::milliseconds(10)); }, .1);
63 62 std::cout << output << std::endl;
64 63 EXPECT_THAT(output, HasSubstr("ms"));
65 64 }
... ...
tests/app_helper.hpp
... ... @@ -20,27 +20,23 @@ struct TApp : public ::testing::Test {
20 20 std::reverse(std::begin(newargs), std::end(newargs));
21 21 return app.parse(newargs);
22 22 }
23   -
24 23 };
25 24  
26   -
27 25 class TempFile {
28 26 std::string _name;
29 27  
30   -public:
31   -
  28 + public:
32 29 TempFile(std::string name) : _name(name) {
33 30 if(!CLI::NonexistentPath(_name))
34 31 throw std::runtime_error(_name);
35   -
36 32 }
37 33  
38 34 ~TempFile() {
39 35 std::remove(_name.c_str()); // Doesn't matter if returns 0 or not
40 36 }
41 37  
42   - operator const std::string& () const {return _name;}
43   - const char* c_str() const {return _name.c_str();}
  38 + operator const std::string &() const { return _name; }
  39 + const char *c_str() const { return _name.c_str(); }
44 40 };
45 41  
46 42 inline void put_env(std::string name, std::string value) {
... ... @@ -58,4 +54,3 @@ inline void unset_env(std::string name) {
58 54 unsetenv(name.c_str());
59 55 #endif
60 56 }
61   -
... ...
tests/link_test_1.cpp
1 1 #include "CLI/CLI.hpp"
2 2 #include "CLI/Timer.hpp"
3 3  
4   -int do_nothing() {
5   - return 7;
6   -}
  4 +int do_nothing() { return 7; }
... ...
tests/link_test_2.cpp
... ... @@ -9,4 +9,3 @@ TEST(Link, DoNothing) {
9 9 int a = do_nothing();
10 10 EXPECT_EQ(7, a);
11 11 }
12   -
... ...