Commit 8725de6706ea495e3bed6694a9977eb4d850995b

Authored by Henry Fredrick Schreiner
1 parent 22612c51

Fixes to enable windows compat

CMakeLists.txt
... ... @@ -15,7 +15,7 @@ endif()
15 15  
16 16 # Be moderately paranoid with flags
17 17 if(CMAKE_COMPILER_IS_GNUCC)
18   - add_definitions("-Wall -Wextra")
  18 + add_definitions("-Wall -Wextra -pedantic")
19 19 endif()
20 20 if(MSVC)
21 21 add_definitions("/W4")
... ...
include/CLI/App.hpp
... ... @@ -112,9 +112,9 @@ public:
112 112 }
113 113  
114 114 /// Add a subcommand. Like the constructor, you can override the help message addition by setting help=false
115   - App* add_subcommand(std::string name, std::string description="", bool help=true) {
  115 + App* add_subcommand(std::string name_, std::string description="", bool help=true) {
116 116 subcommands.emplace_back(new App(description, help));
117   - subcommands.back()->name = name;
  117 + subcommands.back()->name = name_;
118 118 return subcommands.back().get();
119 119 }
120 120  
... ... @@ -132,17 +132,17 @@ public:
132 132 * program.add_option("filename", filename, "description of filename");
133 133 */
134 134 Option* add_option(
135   - std::string name,
  135 + std::string name_,
136 136 callback_t callback,
137 137 std::string description="",
138 138 bool defaulted=false
139 139 ) {
140   - Option myopt{name, description, callback, defaulted};
  140 + Option myopt{name_, description, callback, defaulted};
141 141 if(std::find_if(std::begin(options), std::end(options),
142 142 [&myopt](const Option_p &v){return *v == myopt;}) == std::end(options)) {
143 143 options.emplace_back();
144 144 Option_p& option = options.back();
145   - option.reset(new Option(name, description, callback, defaulted));
  145 + option.reset(new Option(name_, description, callback, defaulted));
146 146 return option.get();
147 147 } else
148 148 throw OptionAlreadyAdded(myopt.get_name());
... ... @@ -152,7 +152,7 @@ public:
152 152 /// Add option for string
153 153 template<typename T, enable_if_t<!is_vector<T>::value, detail::enabler> = detail::dummy>
154 154 Option* add_option(
155   - std::string name,
  155 + std::string name_,
156 156 T &variable, ///< The variable to set
157 157 std::string description="",
158 158 bool defaulted=false
... ... @@ -169,7 +169,7 @@ public:
169 169 return detail::lexical_cast(res[0][0], variable);
170 170 };
171 171  
172   - Option* retval = add_option(name, fun, description, defaulted);
  172 + Option* retval = add_option(name_, fun, description, defaulted);
173 173 retval->typeval = detail::type_name<T>();
174 174 if(defaulted) {
175 175 std::stringstream out;
... ... @@ -182,7 +182,7 @@ public:
182 182 /// Add option for vector of results
183 183 template<typename T>
184 184 Option* add_option(
185   - std::string name,
  185 + std::string name_,
186 186 std::vector<T> &variable, ///< The variable vector to set
187 187 std::string description="",
188 188 bool defaulted=false
... ... @@ -199,7 +199,7 @@ public:
199 199 return variable.size() > 0 && retval;
200 200 };
201 201  
202   - Option* retval = add_option(name, fun, description, defaulted);
  202 + Option* retval = add_option(name_, fun, description, defaulted);
203 203 retval->allow_vector = true;
204 204 retval->_expected = -1;
205 205 retval->typeval = detail::type_name<T>();
... ... @@ -211,14 +211,14 @@ public:
211 211  
212 212 /// Add option for flag
213 213 Option* add_flag(
214   - std::string name,
  214 + std::string name_,
215 215 std::string description=""
216 216 ) {
217 217 CLI::callback_t fun = [](CLI::results_t){
218 218 return true;
219 219 };
220 220  
221   - Option* opt = add_option(name, fun, description, false);
  221 + Option* opt = add_option(name_, fun, description, false);
222 222 if(opt->get_positional())
223 223 throw IncorrectConstruction("Flags cannot be positional");
224 224 opt->_expected = 0;
... ... @@ -229,7 +229,7 @@ public:
229 229 template<typename T,
230 230 enable_if_t<std::is_integral<T>::value && !is_bool<T>::value, detail::enabler> = detail::dummy>
231 231 Option* add_flag(
232   - std::string name,
  232 + std::string name_,
233 233 T &count, ///< A varaible holding the count
234 234 std::string description=""
235 235 ) {
... ... @@ -240,7 +240,7 @@ public:
240 240 return true;
241 241 };
242 242  
243   - Option* opt = add_option(name, fun, description, false);
  243 + Option* opt = add_option(name_, fun, description, false);
244 244 if(opt->get_positional())
245 245 throw IncorrectConstruction("Flags cannot be positional");
246 246 opt->_expected = 0;
... ... @@ -251,7 +251,7 @@ public:
251 251 template<typename T,
252 252 enable_if_t<is_bool<T>::value, detail::enabler> = detail::dummy>
253 253 Option* add_flag(
254   - std::string name,
  254 + std::string name_,
255 255 T &count, ///< A varaible holding true if passed
256 256 std::string description=""
257 257 ) {
... ... @@ -262,7 +262,7 @@ public:
262 262 return res.size() == 1;
263 263 };
264 264  
265   - Option* opt = add_option(name, fun, description, false);
  265 + Option* opt = add_option(name_, fun, description, false);
266 266 if(opt->get_positional())
267 267 throw IncorrectConstruction("Flags cannot be positional");
268 268 opt->_expected = 0;
... ... @@ -273,7 +273,7 @@ public:
273 273 /// Add set of options
274 274 template<typename T>
275 275 Option* add_set(
276   - std::string name,
  276 + std::string name_,
277 277 T &member, ///< The selected member of the set
278 278 std::set<T> _options, ///< The set of posibilities
279 279 std::string description="",
... ... @@ -293,7 +293,7 @@ public:
293 293 return std::find(std::begin(_options), std::end(_options), member) != std::end(_options);
294 294 };
295 295  
296   - Option* retval = add_option(name, fun, description, defaulted);
  296 + Option* retval = add_option(name_, fun, description, defaulted);
297 297 retval->typeval = detail::type_name<T>();
298 298 retval->typeval += " in {" + detail::join(_options) + "}";
299 299 if(defaulted) {
... ... @@ -306,7 +306,7 @@ public:
306 306  
307 307  
308 308 /// Add a configuration ini file option
309   - Option* add_config(std::string name="--config",
  309 + Option* add_config(std::string name_="--config",
310 310 std::string default_filename="",
311 311 std::string help="Read an ini file",
312 312 bool required=false) {
... ... @@ -316,7 +316,7 @@ public:
316 316 remove_option(ini_setting);
317 317 ini_file = default_filename;
318 318 ini_required = required;
319   - ini_setting = add_option(name, ini_file, help, default_filename!="");
  319 + ini_setting = add_option(name_, ini_file, help, default_filename!="");
320 320 return ini_setting;
321 321 }
322 322  
... ... @@ -366,13 +366,13 @@ public:
366 366 }
367 367  
368 368 /// Counts the number of times the given option was passed.
369   - int count(std::string name) const {
  369 + int count(std::string name_) const {
370 370 for(const Option_p &opt : options) {
371   - if(opt->check_name(name)) {
  371 + if(opt->check_name(name_)) {
372 372 return opt->count();
373 373 }
374 374 }
375   - throw OptionNotFound(name);
  375 + throw OptionNotFound(name_);
376 376 }
377 377  
378 378 /// Makes a help message, with a column `wid` for column 1
... ... @@ -547,7 +547,7 @@ protected:
547 547 _parse_long(values, false);
548 548 }
549 549  
550   - } catch (const FileError &e) {
  550 + } catch (const FileError &) {
551 551 if(ini_required)
552 552 throw;
553 553 }
... ... @@ -615,16 +615,16 @@ protected:
615 615 void _parse_short(std::vector<std::string> &args) {
616 616 std::string current = args.back();
617 617  
618   - std::string name;
  618 + std::string name_;
619 619 std::string rest;
620   - if(!detail::split_short(current, name, rest))
  620 + if(!detail::split_short(current, name_, rest))
621 621 throw HorribleError("Short");
622 622 args.pop_back();
623 623  
624   - auto op_ptr = std::find_if(std::begin(options), std::end(options), [name](const Option_p &opt){return opt->check_sname(name);});
  624 + auto op_ptr = std::find_if(std::begin(options), std::end(options), [name_](const Option_p &opt){return opt->check_sname(name_);});
625 625  
626 626 if(op_ptr == std::end(options)) {
627   - missing_options.push_back("-" + name);
  627 + missing_options.push_back("-" + name_);
628 628 return;
629 629 }
630 630  
... ... @@ -651,9 +651,9 @@ protected:
651 651 }
652 652 } else while(num>0 && args.size() > 0) {
653 653 num--;
654   - std::string current = args.back();
  654 + std::string current_ = args.back();
655 655 args.pop_back();
656   - op->add_result(vnum,current);
  656 + op->add_result(vnum, current_);
657 657 }
658 658  
659 659 if(rest != "") {
... ... @@ -666,16 +666,16 @@ protected:
666 666 void _parse_long(std::vector<std::string> &args, bool overwrite=true) {
667 667 std::string current = args.back();
668 668  
669   - std::string name;
  669 + std::string name_;
670 670 std::string value;
671   - if(!detail::split_long(current, name, value))
  671 + if(!detail::split_long(current, name_, value))
672 672 throw HorribleError("Long");
673 673 args.pop_back();
674 674  
675   - auto op_ptr = std::find_if(std::begin(options), std::end(options), [name](const Option_p &v){return v->check_lname(name);});
  675 + auto op_ptr = std::find_if(std::begin(options), std::end(options), [name_](const Option_p &v){return v->check_lname(name_);});
676 676  
677 677 if(op_ptr == std::end(options)) {
678   - missing_options.push_back("--" + name);
  678 + missing_options.push_back("--" + name_);
679 679 return;
680 680 }
681 681  
... ...
include/CLI/StringTools.hpp
... ... @@ -94,13 +94,13 @@ void format_help(std::stringstream &amp;out, std::string name, std::string descripti
94 94 /// Verify the first character of an option
95 95 template<typename T>
96 96 bool valid_first_char(T c) {
97   - return std::isalpha(c) || c=='_';
  97 + return std::isalpha(c, std::locale::classic()) || c=='_';
98 98 }
99 99  
100 100 /// Verify following characters of an option
101 101 template<typename T>
102 102 bool valid_later_char(T c) {
103   - return std::isalnum(c) || c=='_' || c=='.' || c=='-';
  103 + return std::isalnum(c, std::locale::classic()) || c=='_' || c=='.' || c=='-';
104 104 }
105 105  
106 106 /// Verify an option name
... ...
include/CLI/Validators.hpp
... ... @@ -27,7 +27,7 @@ namespace CLI {
27 27 bool ExistingFile(std::string filename) {
28 28 struct stat buffer;
29 29 bool exist = stat(filename.c_str(), &buffer) == 0;
30   - bool is_dir = buffer.st_mode & S_IFDIR;
  30 + bool is_dir = buffer.st_mode & S_IFDIR != 0;
31 31 if(!exist) {
32 32 std::cerr << "File does not exist: " << filename << std::endl;
33 33 return false;
... ... @@ -43,7 +43,7 @@ bool ExistingFile(std::string filename) {
43 43 bool ExistingDirectory(std::string filename) {
44 44 struct stat buffer;
45 45 bool exist = stat(filename.c_str(), &buffer) == 0;
46   - bool is_dir = buffer.st_mode & S_IFDIR;
  46 + bool is_dir = buffer.st_mode & S_IFDIR != 0;
47 47 if(!exist) {
48 48 std::cerr << "Directory does not exist: " << filename << std::endl;
49 49 return false;
... ...
tests/AppTest.cpp
... ... @@ -250,7 +250,7 @@ TEST_F(TApp, Reset) {
250 250  
251 251 EXPECT_EQ(1, app.count("--simple"));
252 252 EXPECT_EQ(1, app.count("-d"));
253   - EXPECT_FLOAT_EQ(1.2, doub);
  253 + EXPECT_DOUBLE_EQ(1.2, doub);
254 254  
255 255 app.reset();
256 256  
... ... @@ -261,7 +261,7 @@ TEST_F(TApp, Reset) {
261 261  
262 262 EXPECT_EQ(1, app.count("--simple"));
263 263 EXPECT_EQ(1, app.count("-d"));
264   - EXPECT_FLOAT_EQ(1.2, doub);
  264 + EXPECT_DOUBLE_EQ(1.2, doub);
265 265  
266 266 }
267 267  
... ... @@ -489,7 +489,7 @@ TEST_F(TApp, RequiresChainedFlags) {
489 489  
490 490 TEST_F(TApp, Env) {
491 491  
492   - setenv("CLI11_TEST_ENV_TMP", "2", true);
  492 + put_env("CLI11_TEST_ENV_TMP", "2", true);
493 493  
494 494 int val=1;
495 495 CLI::Option* vopt = app.add_option("--tmp", val)->envname("CLI11_TEST_ENV_TMP");
... ... @@ -504,7 +504,7 @@ TEST_F(TApp, Env) {
504 504 EXPECT_NO_THROW(run());
505 505  
506 506 app.reset();
507   - unsetenv("CLI11_TEST_ENV_TMP");
  507 + unset_env("CLI11_TEST_ENV_TMP");
508 508 EXPECT_THROW(run(), CLI::RequiredError);
509 509 }
510 510  
... ...
tests/app_helper.hpp
... ... @@ -42,3 +42,20 @@ public:
42 42 operator const std::string& () const {return _name;}
43 43 const char* c_str() const {return _name.c_str();}
44 44 };
  45 +
  46 +inline void put_env(std::string name, std::string value) {
  47 +#ifdef _MSC_VER
  48 + _putenv_s(name.c_str(), value.c_str());
  49 +#else
  50 + setenv(name.c_str(), value.c_str(), 1);
  51 +#endif
  52 +}
  53 +
  54 +inline void unset_env(std::string name) {
  55 +#ifdef _MSC_VER
  56 + _putenv_s(name.c_str(), "");
  57 +#else
  58 + unsetenv(name.c_str());
  59 +#endif
  60 +}
  61 +
... ...