Commit 546d5ec2378f42b3690f1fa7861c952250c9d972
Committed by
Henry Schreiner
1 parent
17d05b00
clear up some additional Wshadow warnings on older compilers (#232)
* clear up some additional Wshadow warnings on older compilers * clear up a few more Wshadow warnings in option * add extra test for delimiter in add_option_function call. * clear up a warning from the test
Showing
4 changed files
with
112 additions
and
86 deletions
CMakeLists.txt
| @@ -36,7 +36,7 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) | @@ -36,7 +36,7 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) | ||
| 36 | if(MSVC) | 36 | if(MSVC) |
| 37 | add_definitions("/W4") | 37 | add_definitions("/W4") |
| 38 | else() | 38 | else() |
| 39 | - add_definitions(-Wall -Wextra -pedantic) | 39 | + add_definitions(-Wall -Wextra -pedantic -Wshadow) |
| 40 | endif() | 40 | endif() |
| 41 | 41 | ||
| 42 | if(CMAKE_VERSION VERSION_GREATER 3.6) | 42 | if(CMAKE_VERSION VERSION_GREATER 3.6) |
include/CLI/App.hpp
| @@ -193,8 +193,8 @@ class App { | @@ -193,8 +193,8 @@ class App { | ||
| 193 | ///@} | 193 | ///@} |
| 194 | 194 | ||
| 195 | /// Special private constructor for subcommand | 195 | /// Special private constructor for subcommand |
| 196 | - App(std::string description, std::string app_name, App *parent) | ||
| 197 | - : name_(std::move(app_name)), description_(std::move(description)), parent_(parent) { | 196 | + App(std::string app_description, std::string app_name, App *parent) |
| 197 | + : name_(std::move(app_name)), description_(std::move(app_description)), parent_(parent) { | ||
| 198 | // Inherit if not from a nullptr | 198 | // Inherit if not from a nullptr |
| 199 | if(parent_ != nullptr) { | 199 | if(parent_ != nullptr) { |
| 200 | if(parent_->help_ptr_ != nullptr) | 200 | if(parent_->help_ptr_ != nullptr) |
| @@ -228,7 +228,8 @@ class App { | @@ -228,7 +228,8 @@ class App { | ||
| 228 | ///@{ | 228 | ///@{ |
| 229 | 229 | ||
| 230 | /// Create a new program. Pass in the same arguments as main(), along with a help string. | 230 | /// Create a new program. Pass in the same arguments as main(), along with a help string. |
| 231 | - explicit App(std::string description = "", std::string app_name = "") : App(description, app_name, nullptr) { | 231 | + explicit App(std::string app_description = "", std::string app_name = "") |
| 232 | + : App(app_description, app_name, nullptr) { | ||
| 232 | set_help_flag("-h,--help", "Print this help message and exit"); | 233 | set_help_flag("-h,--help", "Print this help message and exit"); |
| 233 | } | 234 | } |
| 234 | 235 | ||
| @@ -353,16 +354,16 @@ class App { | @@ -353,16 +354,16 @@ class App { | ||
| 353 | /// | 354 | /// |
| 354 | Option *add_option(std::string option_name, | 355 | Option *add_option(std::string option_name, |
| 355 | callback_t option_callback, | 356 | callback_t option_callback, |
| 356 | - std::string description = "", | 357 | + std::string option_description = "", |
| 357 | bool defaulted = false) { | 358 | bool defaulted = false) { |
| 358 | - Option myopt{option_name, description, option_callback, defaulted, this}; | 359 | + Option myopt{option_name, option_description, option_callback, defaulted, this}; |
| 359 | 360 | ||
| 360 | if(std::find_if(std::begin(options_), std::end(options_), [&myopt](const Option_p &v) { | 361 | if(std::find_if(std::begin(options_), std::end(options_), [&myopt](const Option_p &v) { |
| 361 | return *v == myopt; | 362 | return *v == myopt; |
| 362 | }) == std::end(options_)) { | 363 | }) == std::end(options_)) { |
| 363 | options_.emplace_back(); | 364 | options_.emplace_back(); |
| 364 | Option_p &option = options_.back(); | 365 | Option_p &option = options_.back(); |
| 365 | - option.reset(new Option(option_name, description, option_callback, defaulted, this)); | 366 | + option.reset(new Option(option_name, option_description, option_callback, defaulted, this)); |
| 366 | option_defaults_.copy_to(option.get()); | 367 | option_defaults_.copy_to(option.get()); |
| 367 | return option.get(); | 368 | return option.get(); |
| 368 | } else | 369 | } else |
| @@ -373,11 +374,11 @@ class App { | @@ -373,11 +374,11 @@ class App { | ||
| 373 | template <typename T, enable_if_t<!is_vector<T>::value, detail::enabler> = detail::dummy> | 374 | template <typename T, enable_if_t<!is_vector<T>::value, detail::enabler> = detail::dummy> |
| 374 | Option *add_option(std::string option_name, | 375 | Option *add_option(std::string option_name, |
| 375 | T &variable, ///< The variable to set | 376 | T &variable, ///< The variable to set |
| 376 | - std::string description = "") { | 377 | + std::string option_description = "") { |
| 377 | 378 | ||
| 378 | CLI::callback_t fun = [&variable](CLI::results_t res) { return detail::lexical_cast(res[0], variable); }; | 379 | CLI::callback_t fun = [&variable](CLI::results_t res) { return detail::lexical_cast(res[0], variable); }; |
| 379 | 380 | ||
| 380 | - Option *opt = add_option(option_name, fun, description, false); | 381 | + Option *opt = add_option(option_name, fun, option_description, false); |
| 381 | opt->type_name(detail::type_name<T>()); | 382 | opt->type_name(detail::type_name<T>()); |
| 382 | return opt; | 383 | return opt; |
| 383 | } | 384 | } |
| @@ -386,7 +387,7 @@ class App { | @@ -386,7 +387,7 @@ class App { | ||
| 386 | template <typename T, enable_if_t<!is_vector<T>::value, detail::enabler> = detail::dummy> | 387 | template <typename T, enable_if_t<!is_vector<T>::value, detail::enabler> = detail::dummy> |
| 387 | Option *add_option_function(std::string option_name, | 388 | Option *add_option_function(std::string option_name, |
| 388 | const std::function<bool(const T &)> &func, ///< the callback to execute | 389 | const std::function<bool(const T &)> &func, ///< the callback to execute |
| 389 | - std::string description = "") { | 390 | + std::string option_description = "") { |
| 390 | 391 | ||
| 391 | CLI::callback_t fun = [func](CLI::results_t res) { | 392 | CLI::callback_t fun = [func](CLI::results_t res) { |
| 392 | T variable; | 393 | T variable; |
| @@ -397,7 +398,7 @@ class App { | @@ -397,7 +398,7 @@ class App { | ||
| 397 | return result; | 398 | return result; |
| 398 | }; | 399 | }; |
| 399 | 400 | ||
| 400 | - Option *opt = add_option(option_name, std::move(fun), description, false); | 401 | + Option *opt = add_option(option_name, std::move(fun), option_description, false); |
| 401 | opt->type_name(detail::type_name<T>()); | 402 | opt->type_name(detail::type_name<T>()); |
| 402 | return opt; | 403 | return opt; |
| 403 | } | 404 | } |
| @@ -406,12 +407,12 @@ class App { | @@ -406,12 +407,12 @@ class App { | ||
| 406 | template <typename T, enable_if_t<!is_vector<T>::value, detail::enabler> = detail::dummy> | 407 | template <typename T, enable_if_t<!is_vector<T>::value, detail::enabler> = detail::dummy> |
| 407 | Option *add_option(std::string option_name, | 408 | Option *add_option(std::string option_name, |
| 408 | T &variable, ///< The variable to set | 409 | T &variable, ///< The variable to set |
| 409 | - std::string description, | 410 | + std::string option_description, |
| 410 | bool defaulted) { | 411 | bool defaulted) { |
| 411 | 412 | ||
| 412 | CLI::callback_t fun = [&variable](CLI::results_t res) { return detail::lexical_cast(res[0], variable); }; | 413 | CLI::callback_t fun = [&variable](CLI::results_t res) { return detail::lexical_cast(res[0], variable); }; |
| 413 | 414 | ||
| 414 | - Option *opt = add_option(option_name, fun, description, defaulted); | 415 | + Option *opt = add_option(option_name, fun, option_description, defaulted); |
| 415 | opt->type_name(detail::type_name<T>()); | 416 | opt->type_name(detail::type_name<T>()); |
| 416 | if(defaulted) { | 417 | if(defaulted) { |
| 417 | std::stringstream out; | 418 | std::stringstream out; |
| @@ -425,14 +426,14 @@ class App { | @@ -425,14 +426,14 @@ class App { | ||
| 425 | template <typename T> | 426 | template <typename T> |
| 426 | Option *add_option(std::string option_name, | 427 | Option *add_option(std::string option_name, |
| 427 | std::vector<T> &variable, ///< The variable vector to set | 428 | std::vector<T> &variable, ///< The variable vector to set |
| 428 | - std::string description = "", | 429 | + std::string option_description = "", |
| 429 | char delimiter = '\0') { | 430 | char delimiter = '\0') { |
| 430 | 431 | ||
| 431 | CLI::callback_t fun = [&variable, delimiter](CLI::results_t res) { | 432 | CLI::callback_t fun = [&variable, delimiter](CLI::results_t res) { |
| 432 | bool retval = true; | 433 | bool retval = true; |
| 433 | variable.clear(); | 434 | variable.clear(); |
| 434 | for(const auto &elem : res) { | 435 | for(const auto &elem : res) { |
| 435 | - if(delimiter != '\0') { | 436 | + if((delimiter != '\0') && (elem.find_first_of(delimiter) != std::string::npos)) { |
| 436 | for(const auto &var : CLI::detail::split(elem, delimiter)) { | 437 | for(const auto &var : CLI::detail::split(elem, delimiter)) { |
| 437 | if(!var.empty()) { | 438 | if(!var.empty()) { |
| 438 | variable.emplace_back(); | 439 | variable.emplace_back(); |
| @@ -447,7 +448,7 @@ class App { | @@ -447,7 +448,7 @@ class App { | ||
| 447 | return (!variable.empty()) && retval; | 448 | return (!variable.empty()) && retval; |
| 448 | }; | 449 | }; |
| 449 | 450 | ||
| 450 | - Option *opt = add_option(option_name, fun, description, false); | 451 | + Option *opt = add_option(option_name, fun, option_description, false); |
| 451 | opt->type_name(detail::type_name<T>())->type_size(-1); | 452 | opt->type_name(detail::type_name<T>())->type_size(-1); |
| 452 | return opt; | 453 | return opt; |
| 453 | } | 454 | } |
| @@ -456,7 +457,7 @@ class App { | @@ -456,7 +457,7 @@ class App { | ||
| 456 | template <typename T> | 457 | template <typename T> |
| 457 | Option *add_option(std::string option_name, | 458 | Option *add_option(std::string option_name, |
| 458 | std::vector<T> &variable, ///< The variable vector to set | 459 | std::vector<T> &variable, ///< The variable vector to set |
| 459 | - std::string description, | 460 | + std::string option_description, |
| 460 | bool defaulted, | 461 | bool defaulted, |
| 461 | char delimiter = '\0') { | 462 | char delimiter = '\0') { |
| 462 | 463 | ||
| @@ -464,7 +465,7 @@ class App { | @@ -464,7 +465,7 @@ class App { | ||
| 464 | bool retval = true; | 465 | bool retval = true; |
| 465 | variable.clear(); | 466 | variable.clear(); |
| 466 | for(const auto &elem : res) { | 467 | for(const auto &elem : res) { |
| 467 | - if(delimiter != '\0') { | 468 | + if((delimiter != '\0') && (elem.find_first_of(delimiter) != std::string::npos)) { |
| 468 | for(const auto &var : CLI::detail::split(elem, delimiter)) { | 469 | for(const auto &var : CLI::detail::split(elem, delimiter)) { |
| 469 | if(!var.empty()) { | 470 | if(!var.empty()) { |
| 470 | variable.emplace_back(); | 471 | variable.emplace_back(); |
| @@ -479,7 +480,7 @@ class App { | @@ -479,7 +480,7 @@ class App { | ||
| 479 | return (!variable.empty()) && retval; | 480 | return (!variable.empty()) && retval; |
| 480 | }; | 481 | }; |
| 481 | 482 | ||
| 482 | - Option *opt = add_option(option_name, fun, description, defaulted); | 483 | + Option *opt = add_option(option_name, fun, option_description, defaulted); |
| 483 | opt->type_name(detail::type_name<T>())->type_size(-1); | 484 | opt->type_name(detail::type_name<T>())->type_size(-1); |
| 484 | if(defaulted) | 485 | if(defaulted) |
| 485 | opt->default_str("[" + detail::join(variable) + "]"); | 486 | opt->default_str("[" + detail::join(variable) + "]"); |
| @@ -490,15 +491,25 @@ class App { | @@ -490,15 +491,25 @@ class App { | ||
| 490 | template <typename T, enable_if_t<is_vector<T>::value, detail::enabler> = detail::dummy> | 491 | template <typename T, enable_if_t<is_vector<T>::value, detail::enabler> = detail::dummy> |
| 491 | Option *add_option_function(std::string option_name, | 492 | Option *add_option_function(std::string option_name, |
| 492 | const std::function<bool(const T &)> &func, ///< the callback to execute | 493 | const std::function<bool(const T &)> &func, ///< the callback to execute |
| 493 | - std::string description = "") { | 494 | + std::string option_description = "", |
| 495 | + char delimiter = '\0') { | ||
| 494 | 496 | ||
| 495 | - CLI::callback_t fun = [func](CLI::results_t res) { | 497 | + CLI::callback_t fun = [func, delimiter](CLI::results_t res) { |
| 496 | T values; | 498 | T values; |
| 497 | bool retval = true; | 499 | bool retval = true; |
| 498 | values.reserve(res.size()); | 500 | values.reserve(res.size()); |
| 499 | - for(const auto &a : res) { | ||
| 500 | - values.emplace_back(); | ||
| 501 | - retval &= detail::lexical_cast(a, values.back()); | 501 | + for(const auto &elem : res) { |
| 502 | + if((delimiter != '\0') && (elem.find_first_of(delimiter) != std::string::npos)) { | ||
| 503 | + for(const auto &var : CLI::detail::split(elem, delimiter)) { | ||
| 504 | + if(!var.empty()) { | ||
| 505 | + values.emplace_back(); | ||
| 506 | + retval &= detail::lexical_cast(var, values.back()); | ||
| 507 | + } | ||
| 508 | + } | ||
| 509 | + } else { | ||
| 510 | + values.emplace_back(); | ||
| 511 | + retval &= detail::lexical_cast(elem, values.back()); | ||
| 512 | + } | ||
| 502 | } | 513 | } |
| 503 | if(retval) { | 514 | if(retval) { |
| 504 | return func(values); | 515 | return func(values); |
| @@ -506,13 +517,13 @@ class App { | @@ -506,13 +517,13 @@ class App { | ||
| 506 | return retval; | 517 | return retval; |
| 507 | }; | 518 | }; |
| 508 | 519 | ||
| 509 | - Option *opt = add_option(option_name, std::move(fun), description, false); | 520 | + Option *opt = add_option(option_name, std::move(fun), std::move(option_description), false); |
| 510 | opt->type_name(detail::type_name<T>())->type_size(-1); | 521 | opt->type_name(detail::type_name<T>())->type_size(-1); |
| 511 | return opt; | 522 | return opt; |
| 512 | } | 523 | } |
| 513 | 524 | ||
| 514 | /// Set a help flag, replace the existing one if present | 525 | /// Set a help flag, replace the existing one if present |
| 515 | - Option *set_help_flag(std::string flag_name = "", std::string description = "") { | 526 | + Option *set_help_flag(std::string flag_name = "", std::string help_description = "") { |
| 516 | if(help_ptr_ != nullptr) { | 527 | if(help_ptr_ != nullptr) { |
| 517 | remove_option(help_ptr_); | 528 | remove_option(help_ptr_); |
| 518 | help_ptr_ = nullptr; | 529 | help_ptr_ = nullptr; |
| @@ -520,7 +531,7 @@ class App { | @@ -520,7 +531,7 @@ class App { | ||
| 520 | 531 | ||
| 521 | // Empty name will simply remove the help flag | 532 | // Empty name will simply remove the help flag |
| 522 | if(!flag_name.empty()) { | 533 | if(!flag_name.empty()) { |
| 523 | - help_ptr_ = add_flag(flag_name, description); | 534 | + help_ptr_ = add_flag(flag_name, std::move(help_description)); |
| 524 | help_ptr_->configurable(false); | 535 | help_ptr_->configurable(false); |
| 525 | } | 536 | } |
| 526 | 537 | ||
| @@ -528,7 +539,7 @@ class App { | @@ -528,7 +539,7 @@ class App { | ||
| 528 | } | 539 | } |
| 529 | 540 | ||
| 530 | /// Set a help all flag, replaced the existing one if present | 541 | /// Set a help all flag, replaced the existing one if present |
| 531 | - Option *set_help_all_flag(std::string help_name = "", std::string description = "") { | 542 | + Option *set_help_all_flag(std::string help_name = "", std::string help_description = "") { |
| 532 | if(help_all_ptr_ != nullptr) { | 543 | if(help_all_ptr_ != nullptr) { |
| 533 | remove_option(help_all_ptr_); | 544 | remove_option(help_all_ptr_); |
| 534 | help_all_ptr_ = nullptr; | 545 | help_all_ptr_ = nullptr; |
| @@ -536,7 +547,7 @@ class App { | @@ -536,7 +547,7 @@ class App { | ||
| 536 | 547 | ||
| 537 | // Empty name will simply remove the help all flag | 548 | // Empty name will simply remove the help all flag |
| 538 | if(!help_name.empty()) { | 549 | if(!help_name.empty()) { |
| 539 | - help_all_ptr_ = add_flag(help_name, description); | 550 | + help_all_ptr_ = add_flag(help_name, std::move(help_description)); |
| 540 | help_all_ptr_->configurable(false); | 551 | help_all_ptr_->configurable(false); |
| 541 | } | 552 | } |
| 542 | 553 | ||
| @@ -544,9 +555,9 @@ class App { | @@ -544,9 +555,9 @@ class App { | ||
| 544 | } | 555 | } |
| 545 | 556 | ||
| 546 | /// Add option for flag | 557 | /// Add option for flag |
| 547 | - Option *add_flag(std::string flag_name, std::string description = "") { | 558 | + Option *add_flag(std::string flag_name, std::string flag_description = "") { |
| 548 | CLI::callback_t fun = [](CLI::results_t) { return true; }; | 559 | CLI::callback_t fun = [](CLI::results_t) { return true; }; |
| 549 | - Option *opt = add_option(flag_name, fun, description, false); | 560 | + Option *opt = add_option(flag_name, fun, flag_description, false); |
| 550 | if(opt->get_positional()) | 561 | if(opt->get_positional()) |
| 551 | throw IncorrectConstruction::PositionalFlag(flag_name); | 562 | throw IncorrectConstruction::PositionalFlag(flag_name); |
| 552 | opt->type_size(0); | 563 | opt->type_size(0); |
| @@ -558,7 +569,7 @@ class App { | @@ -558,7 +569,7 @@ class App { | ||
| 558 | enable_if_t<std::is_integral<T>::value && !is_bool<T>::value, detail::enabler> = detail::dummy> | 569 | enable_if_t<std::is_integral<T>::value && !is_bool<T>::value, detail::enabler> = detail::dummy> |
| 559 | Option *add_flag(std::string flag_name, | 570 | Option *add_flag(std::string flag_name, |
| 560 | T &flag_count, ///< A variable holding the count | 571 | T &flag_count, ///< A variable holding the count |
| 561 | - std::string description = "") { | 572 | + std::string flag_description = "") { |
| 562 | flag_count = 0; | 573 | flag_count = 0; |
| 563 | Option *opt; | 574 | Option *opt; |
| 564 | CLI::callback_t fun = [&flag_count](CLI::results_t res) { | 575 | CLI::callback_t fun = [&flag_count](CLI::results_t res) { |
| @@ -568,10 +579,10 @@ class App { | @@ -568,10 +579,10 @@ class App { | ||
| 568 | if(detail::has_false_flags(flag_name)) { | 579 | if(detail::has_false_flags(flag_name)) { |
| 569 | std::vector<std::string> neg = detail::get_false_flags(flag_name); | 580 | std::vector<std::string> neg = detail::get_false_flags(flag_name); |
| 570 | detail::remove_false_flag_notation(flag_name); | 581 | detail::remove_false_flag_notation(flag_name); |
| 571 | - opt = add_option(flag_name, fun, description, false); | 582 | + opt = add_option(flag_name, fun, flag_description, false); |
| 572 | opt->fnames_ = std::move(neg); | 583 | opt->fnames_ = std::move(neg); |
| 573 | } else { | 584 | } else { |
| 574 | - opt = add_option(flag_name, fun, description, false); | 585 | + opt = add_option(flag_name, fun, flag_description, false); |
| 575 | } | 586 | } |
| 576 | 587 | ||
| 577 | if(opt->get_positional()) | 588 | if(opt->get_positional()) |
| @@ -585,7 +596,7 @@ class App { | @@ -585,7 +596,7 @@ class App { | ||
| 585 | template <typename T, enable_if_t<is_bool<T>::value, detail::enabler> = detail::dummy> | 596 | template <typename T, enable_if_t<is_bool<T>::value, detail::enabler> = detail::dummy> |
| 586 | Option *add_flag(std::string flag_name, | 597 | Option *add_flag(std::string flag_name, |
| 587 | T &flag_result, ///< A variable holding true if passed | 598 | T &flag_result, ///< A variable holding true if passed |
| 588 | - std::string description = "") { | 599 | + std::string flag_description = "") { |
| 589 | flag_result = false; | 600 | flag_result = false; |
| 590 | Option *opt; | 601 | Option *opt; |
| 591 | CLI::callback_t fun = [&flag_result](CLI::results_t res) { | 602 | CLI::callback_t fun = [&flag_result](CLI::results_t res) { |
| @@ -595,10 +606,10 @@ class App { | @@ -595,10 +606,10 @@ class App { | ||
| 595 | if(detail::has_false_flags(flag_name)) { | 606 | if(detail::has_false_flags(flag_name)) { |
| 596 | std::vector<std::string> neg = detail::get_false_flags(flag_name); | 607 | std::vector<std::string> neg = detail::get_false_flags(flag_name); |
| 597 | detail::remove_false_flag_notation(flag_name); | 608 | detail::remove_false_flag_notation(flag_name); |
| 598 | - opt = add_option(flag_name, fun, std::move(description), false); | 609 | + opt = add_option(flag_name, fun, std::move(flag_description), false); |
| 599 | opt->fnames_ = std::move(neg); | 610 | opt->fnames_ = std::move(neg); |
| 600 | } else { | 611 | } else { |
| 601 | - opt = add_option(flag_name, fun, std::move(description), false); | 612 | + opt = add_option(flag_name, fun, std::move(flag_description), false); |
| 602 | } | 613 | } |
| 603 | 614 | ||
| 604 | if(opt->get_positional()) | 615 | if(opt->get_positional()) |
| @@ -611,7 +622,7 @@ class App { | @@ -611,7 +622,7 @@ class App { | ||
| 611 | /// Add option for callback | 622 | /// Add option for callback |
| 612 | Option *add_flag_function(std::string flag_name, | 623 | Option *add_flag_function(std::string flag_name, |
| 613 | std::function<void(int)> function, ///< A function to call, void(size_t) | 624 | std::function<void(int)> function, ///< A function to call, void(size_t) |
| 614 | - std::string description = "") { | 625 | + std::string flag_description = "") { |
| 615 | 626 | ||
| 616 | CLI::callback_t fun = [function](CLI::results_t res) { | 627 | CLI::callback_t fun = [function](CLI::results_t res) { |
| 617 | int flag_count = 0; | 628 | int flag_count = 0; |
| @@ -623,10 +634,10 @@ class App { | @@ -623,10 +634,10 @@ class App { | ||
| 623 | if(detail::has_false_flags(flag_name)) { | 634 | if(detail::has_false_flags(flag_name)) { |
| 624 | std::vector<std::string> neg = detail::get_false_flags(flag_name); | 635 | std::vector<std::string> neg = detail::get_false_flags(flag_name); |
| 625 | detail::remove_false_flag_notation(flag_name); | 636 | detail::remove_false_flag_notation(flag_name); |
| 626 | - opt = add_option(flag_name, fun, std::move(description), false); | 637 | + opt = add_option(flag_name, fun, std::move(flag_description), false); |
| 627 | opt->fnames_ = std::move(neg); | 638 | opt->fnames_ = std::move(neg); |
| 628 | } else { | 639 | } else { |
| 629 | - opt = add_option(flag_name, fun, std::move(description), false); | 640 | + opt = add_option(flag_name, fun, std::move(flag_description), false); |
| 630 | } | 641 | } |
| 631 | 642 | ||
| 632 | if(opt->get_positional()) | 643 | if(opt->get_positional()) |
| @@ -639,8 +650,8 @@ class App { | @@ -639,8 +650,8 @@ class App { | ||
| 639 | /// Add option for callback (C++14 or better only) | 650 | /// Add option for callback (C++14 or better only) |
| 640 | Option *add_flag(std::string flag_name, | 651 | Option *add_flag(std::string flag_name, |
| 641 | std::function<void(int)> function, ///< A function to call, void(int) | 652 | std::function<void(int)> function, ///< A function to call, void(int) |
| 642 | - std::string description = "") { | ||
| 643 | - return add_flag_function(std::move(flag_name), std::move(function), std::move(description)); | 653 | + std::string flag_description = "") { |
| 654 | + return add_flag_function(std::move(flag_name), std::move(function), std::move(flag_description)); | ||
| 644 | } | 655 | } |
| 645 | #endif | 656 | #endif |
| 646 | 657 | ||
| @@ -649,21 +660,21 @@ class App { | @@ -649,21 +660,21 @@ class App { | ||
| 649 | Option *add_set(std::string option_name, | 660 | Option *add_set(std::string option_name, |
| 650 | T &member, ///< The selected member of the set | 661 | T &member, ///< The selected member of the set |
| 651 | std::set<T> options, ///< The set of possibilities | 662 | std::set<T> options, ///< The set of possibilities |
| 652 | - std::string description = "") { | 663 | + std::string option_description = "") { |
| 653 | 664 | ||
| 654 | - Option *opt = add_option(option_name, member, std::move(description)); | 665 | + Option *opt = add_option(option_name, member, std::move(option_description)); |
| 655 | opt->check(IsMember{options}); | 666 | opt->check(IsMember{options}); |
| 656 | return opt; | 667 | return opt; |
| 657 | } | 668 | } |
| 658 | 669 | ||
| 659 | - /// Add set of options (No default, set can be changed afterwords - do not destroy the set) DEPRECATED | 670 | + /// Add set of options (No default, set can be changed afterwards - do not destroy the set) DEPRECATED |
| 660 | template <typename T> | 671 | template <typename T> |
| 661 | Option *add_mutable_set(std::string option_name, | 672 | Option *add_mutable_set(std::string option_name, |
| 662 | T &member, ///< The selected member of the set | 673 | T &member, ///< The selected member of the set |
| 663 | const std::set<T> &options, ///< The set of possibilities | 674 | const std::set<T> &options, ///< The set of possibilities |
| 664 | - std::string description = "") { | 675 | + std::string option_description = "") { |
| 665 | 676 | ||
| 666 | - Option *opt = add_option(option_name, member, std::move(description)); | 677 | + Option *opt = add_option(option_name, member, std::move(option_description)); |
| 667 | opt->check(IsMember{&options}); | 678 | opt->check(IsMember{&options}); |
| 668 | return opt; | 679 | return opt; |
| 669 | } | 680 | } |
| @@ -673,10 +684,10 @@ class App { | @@ -673,10 +684,10 @@ class App { | ||
| 673 | Option *add_set(std::string option_name, | 684 | Option *add_set(std::string option_name, |
| 674 | T &member, ///< The selected member of the set | 685 | T &member, ///< The selected member of the set |
| 675 | std::set<T> options, ///< The set of possibilities | 686 | std::set<T> options, ///< The set of possibilities |
| 676 | - std::string description, | 687 | + std::string option_description, |
| 677 | bool defaulted) { | 688 | bool defaulted) { |
| 678 | 689 | ||
| 679 | - Option *opt = add_option(option_name, member, std::move(description), defaulted); | 690 | + Option *opt = add_option(option_name, member, std::move(option_description), defaulted); |
| 680 | opt->check(IsMember{options}); | 691 | opt->check(IsMember{options}); |
| 681 | return opt; | 692 | return opt; |
| 682 | } | 693 | } |
| @@ -686,10 +697,10 @@ class App { | @@ -686,10 +697,10 @@ class App { | ||
| 686 | Option *add_mutable_set(std::string option_name, | 697 | Option *add_mutable_set(std::string option_name, |
| 687 | T &member, ///< The selected member of the set | 698 | T &member, ///< The selected member of the set |
| 688 | const std::set<T> &options, ///< The set of possibilities | 699 | const std::set<T> &options, ///< The set of possibilities |
| 689 | - std::string description, | 700 | + std::string option_description, |
| 690 | bool defaulted) { | 701 | bool defaulted) { |
| 691 | 702 | ||
| 692 | - Option *opt = add_option(option_name, member, std::move(description), defaulted); | 703 | + Option *opt = add_option(option_name, member, std::move(option_description), defaulted); |
| 693 | opt->check(IsMember{&options}); | 704 | opt->check(IsMember{&options}); |
| 694 | return opt; | 705 | return opt; |
| 695 | } | 706 | } |
| @@ -699,9 +710,9 @@ class App { | @@ -699,9 +710,9 @@ class App { | ||
| 699 | Option *add_set_ignore_case(std::string option_name, | 710 | Option *add_set_ignore_case(std::string option_name, |
| 700 | std::string &member, ///< The selected member of the set | 711 | std::string &member, ///< The selected member of the set |
| 701 | std::set<std::string> options, ///< The set of possibilities | 712 | std::set<std::string> options, ///< The set of possibilities |
| 702 | - std::string description = "") { | 713 | + std::string option_description = "") { |
| 703 | 714 | ||
| 704 | - Option *opt = add_option(option_name, member, std::move(description)); | 715 | + Option *opt = add_option(option_name, member, std::move(option_description)); |
| 705 | opt->transform(IsMember{options, CLI::ignore_case}); | 716 | opt->transform(IsMember{options, CLI::ignore_case}); |
| 706 | return opt; | 717 | return opt; |
| 707 | } | 718 | } |
| @@ -712,9 +723,9 @@ class App { | @@ -712,9 +723,9 @@ class App { | ||
| 712 | Option *add_mutable_set_ignore_case(std::string option_name, | 723 | Option *add_mutable_set_ignore_case(std::string option_name, |
| 713 | std::string &member, ///< The selected member of the set | 724 | std::string &member, ///< The selected member of the set |
| 714 | const std::set<std::string> &options, ///< The set of possibilities | 725 | const std::set<std::string> &options, ///< The set of possibilities |
| 715 | - std::string description = "") { | 726 | + std::string option_description = "") { |
| 716 | 727 | ||
| 717 | - Option *opt = add_option(option_name, member, std::move(description)); | 728 | + Option *opt = add_option(option_name, member, std::move(option_description)); |
| 718 | opt->transform(IsMember{&options, CLI::ignore_case}); | 729 | opt->transform(IsMember{&options, CLI::ignore_case}); |
| 719 | return opt; | 730 | return opt; |
| 720 | } | 731 | } |
| @@ -724,10 +735,10 @@ class App { | @@ -724,10 +735,10 @@ class App { | ||
| 724 | Option *add_set_ignore_case(std::string option_name, | 735 | Option *add_set_ignore_case(std::string option_name, |
| 725 | std::string &member, ///< The selected member of the set | 736 | std::string &member, ///< The selected member of the set |
| 726 | std::set<std::string> options, ///< The set of possibilities | 737 | std::set<std::string> options, ///< The set of possibilities |
| 727 | - std::string description, | 738 | + std::string option_description, |
| 728 | bool defaulted) { | 739 | bool defaulted) { |
| 729 | 740 | ||
| 730 | - Option *opt = add_option(option_name, member, std::move(description), defaulted); | 741 | + Option *opt = add_option(option_name, member, std::move(option_description), defaulted); |
| 731 | opt->transform(IsMember{options, CLI::ignore_case}); | 742 | opt->transform(IsMember{options, CLI::ignore_case}); |
| 732 | return opt; | 743 | return opt; |
| 733 | } | 744 | } |
| @@ -738,10 +749,10 @@ class App { | @@ -738,10 +749,10 @@ class App { | ||
| 738 | Option *add_mutable_set_ignore_case(std::string option_name, | 749 | Option *add_mutable_set_ignore_case(std::string option_name, |
| 739 | std::string &member, ///< The selected member of the set | 750 | std::string &member, ///< The selected member of the set |
| 740 | const std::set<std::string> &options, ///< The set of possibilities | 751 | const std::set<std::string> &options, ///< The set of possibilities |
| 741 | - std::string description, | 752 | + std::string option_description, |
| 742 | bool defaulted) { | 753 | bool defaulted) { |
| 743 | 754 | ||
| 744 | - Option *opt = add_option(option_name, member, std::move(description), defaulted); | 755 | + Option *opt = add_option(option_name, member, std::move(option_description), defaulted); |
| 745 | opt->transform(IsMember{&options, CLI::ignore_case}); | 756 | opt->transform(IsMember{&options, CLI::ignore_case}); |
| 746 | return opt; | 757 | return opt; |
| 747 | } | 758 | } |
| @@ -751,9 +762,9 @@ class App { | @@ -751,9 +762,9 @@ class App { | ||
| 751 | Option *add_set_ignore_underscore(std::string option_name, | 762 | Option *add_set_ignore_underscore(std::string option_name, |
| 752 | std::string &member, ///< The selected member of the set | 763 | std::string &member, ///< The selected member of the set |
| 753 | std::set<std::string> options, ///< The set of possibilities | 764 | std::set<std::string> options, ///< The set of possibilities |
| 754 | - std::string description = "") { | 765 | + std::string option_description = "") { |
| 755 | 766 | ||
| 756 | - Option *opt = add_option(option_name, member, std::move(description)); | 767 | + Option *opt = add_option(option_name, member, std::move(option_description)); |
| 757 | opt->transform(IsMember{options, CLI::ignore_underscore}); | 768 | opt->transform(IsMember{options, CLI::ignore_underscore}); |
| 758 | return opt; | 769 | return opt; |
| 759 | } | 770 | } |
| @@ -764,9 +775,9 @@ class App { | @@ -764,9 +775,9 @@ class App { | ||
| 764 | Option *add_mutable_set_ignore_underscore(std::string option_name, | 775 | Option *add_mutable_set_ignore_underscore(std::string option_name, |
| 765 | std::string &member, ///< The selected member of the set | 776 | std::string &member, ///< The selected member of the set |
| 766 | const std::set<std::string> &options, ///< The set of possibilities | 777 | const std::set<std::string> &options, ///< The set of possibilities |
| 767 | - std::string description = "") { | 778 | + std::string option_description = "") { |
| 768 | 779 | ||
| 769 | - Option *opt = add_option(option_name, member, std::move(description)); | 780 | + Option *opt = add_option(option_name, member, std::move(option_description)); |
| 770 | opt->transform(IsMember{options, CLI::ignore_underscore}); | 781 | opt->transform(IsMember{options, CLI::ignore_underscore}); |
| 771 | return opt; | 782 | return opt; |
| 772 | } | 783 | } |
| @@ -776,10 +787,10 @@ class App { | @@ -776,10 +787,10 @@ class App { | ||
| 776 | Option *add_set_ignore_underscore(std::string option_name, | 787 | Option *add_set_ignore_underscore(std::string option_name, |
| 777 | std::string &member, ///< The selected member of the set | 788 | std::string &member, ///< The selected member of the set |
| 778 | std::set<std::string> options, ///< The set of possibilities | 789 | std::set<std::string> options, ///< The set of possibilities |
| 779 | - std::string description, | 790 | + std::string option_description, |
| 780 | bool defaulted) { | 791 | bool defaulted) { |
| 781 | 792 | ||
| 782 | - Option *opt = add_option(option_name, member, std::move(description), defaulted); | 793 | + Option *opt = add_option(option_name, member, std::move(option_description), defaulted); |
| 783 | opt->transform(IsMember{options, CLI::ignore_underscore}); | 794 | opt->transform(IsMember{options, CLI::ignore_underscore}); |
| 784 | return opt; | 795 | return opt; |
| 785 | } | 796 | } |
| @@ -790,10 +801,10 @@ class App { | @@ -790,10 +801,10 @@ class App { | ||
| 790 | Option *add_mutable_set_ignore_underscore(std::string option_name, | 801 | Option *add_mutable_set_ignore_underscore(std::string option_name, |
| 791 | std::string &member, ///< The selected member of the set | 802 | std::string &member, ///< The selected member of the set |
| 792 | const std::set<std::string> &options, ///< The set of possibilities | 803 | const std::set<std::string> &options, ///< The set of possibilities |
| 793 | - std::string description, | 804 | + std::string option_description, |
| 794 | bool defaulted) { | 805 | bool defaulted) { |
| 795 | 806 | ||
| 796 | - Option *opt = add_option(option_name, member, std::move(description), defaulted); | 807 | + Option *opt = add_option(option_name, member, std::move(option_description), defaulted); |
| 797 | opt->transform(IsMember{&options, CLI::ignore_underscore}); | 808 | opt->transform(IsMember{&options, CLI::ignore_underscore}); |
| 798 | return opt; | 809 | return opt; |
| 799 | } | 810 | } |
| @@ -803,9 +814,9 @@ class App { | @@ -803,9 +814,9 @@ class App { | ||
| 803 | Option *add_set_ignore_case_underscore(std::string option_name, | 814 | Option *add_set_ignore_case_underscore(std::string option_name, |
| 804 | std::string &member, ///< The selected member of the set | 815 | std::string &member, ///< The selected member of the set |
| 805 | std::set<std::string> options, ///< The set of possibilities | 816 | std::set<std::string> options, ///< The set of possibilities |
| 806 | - std::string description = "") { | 817 | + std::string option_description = "") { |
| 807 | 818 | ||
| 808 | - Option *opt = add_option(option_name, member, std::move(description)); | 819 | + Option *opt = add_option(option_name, member, std::move(option_description)); |
| 809 | opt->transform(IsMember{options, CLI::ignore_underscore, CLI::ignore_case}); | 820 | opt->transform(IsMember{options, CLI::ignore_underscore, CLI::ignore_case}); |
| 810 | return opt; | 821 | return opt; |
| 811 | } | 822 | } |
| @@ -817,9 +828,9 @@ class App { | @@ -817,9 +828,9 @@ class App { | ||
| 817 | Option *add_mutable_set_ignore_case_underscore(std::string option_name, | 828 | Option *add_mutable_set_ignore_case_underscore(std::string option_name, |
| 818 | std::string &member, ///< The selected member of the set | 829 | std::string &member, ///< The selected member of the set |
| 819 | const std::set<std::string> &options, ///< The set of possibilities | 830 | const std::set<std::string> &options, ///< The set of possibilities |
| 820 | - std::string description = "") { | 831 | + std::string option_description = "") { |
| 821 | 832 | ||
| 822 | - Option *opt = add_option(option_name, member, std::move(description)); | 833 | + Option *opt = add_option(option_name, member, std::move(option_description)); |
| 823 | opt->transform(IsMember{&options, CLI::ignore_underscore, CLI::ignore_case}); | 834 | opt->transform(IsMember{&options, CLI::ignore_underscore, CLI::ignore_case}); |
| 824 | return opt; | 835 | return opt; |
| 825 | } | 836 | } |
| @@ -829,10 +840,10 @@ class App { | @@ -829,10 +840,10 @@ class App { | ||
| 829 | Option *add_set_ignore_case_underscore(std::string option_name, | 840 | Option *add_set_ignore_case_underscore(std::string option_name, |
| 830 | std::string &member, ///< The selected member of the set | 841 | std::string &member, ///< The selected member of the set |
| 831 | std::set<std::string> options, ///< The set of possibilities | 842 | std::set<std::string> options, ///< The set of possibilities |
| 832 | - std::string description, | 843 | + std::string option_description, |
| 833 | bool defaulted) { | 844 | bool defaulted) { |
| 834 | 845 | ||
| 835 | - Option *opt = add_option(option_name, member, std::move(description), defaulted); | 846 | + Option *opt = add_option(option_name, member, std::move(option_description), defaulted); |
| 836 | opt->transform(IsMember{options, CLI::ignore_underscore, CLI::ignore_case}); | 847 | opt->transform(IsMember{options, CLI::ignore_underscore, CLI::ignore_case}); |
| 837 | return opt; | 848 | return opt; |
| 838 | } | 849 | } |
| @@ -844,10 +855,10 @@ class App { | @@ -844,10 +855,10 @@ class App { | ||
| 844 | Option *add_mutable_set_ignore_case_underscore(std::string option_name, | 855 | Option *add_mutable_set_ignore_case_underscore(std::string option_name, |
| 845 | std::string &member, ///< The selected member of the set | 856 | std::string &member, ///< The selected member of the set |
| 846 | const std::set<std::string> &options, ///< The set of possibilities | 857 | const std::set<std::string> &options, ///< The set of possibilities |
| 847 | - std::string description, | 858 | + std::string option_description, |
| 848 | bool defaulted) { | 859 | bool defaulted) { |
| 849 | 860 | ||
| 850 | - Option *opt = add_option(option_name, member, std::move(description), defaulted); | 861 | + Option *opt = add_option(option_name, member, std::move(option_description), defaulted); |
| 851 | opt->transform(IsMember{&options, CLI::ignore_underscore, CLI::ignore_case}); | 862 | opt->transform(IsMember{&options, CLI::ignore_underscore, CLI::ignore_case}); |
| 852 | return opt; | 863 | return opt; |
| 853 | } | 864 | } |
| @@ -856,7 +867,7 @@ class App { | @@ -856,7 +867,7 @@ class App { | ||
| 856 | template <typename T> | 867 | template <typename T> |
| 857 | Option *add_complex(std::string option_name, | 868 | Option *add_complex(std::string option_name, |
| 858 | T &variable, | 869 | T &variable, |
| 859 | - std::string description = "", | 870 | + std::string option_description = "", |
| 860 | bool defaulted = false, | 871 | bool defaulted = false, |
| 861 | std::string label = "COMPLEX") { | 872 | std::string label = "COMPLEX") { |
| 862 | 873 | ||
| @@ -871,7 +882,7 @@ class App { | @@ -871,7 +882,7 @@ class App { | ||
| 871 | return worked; | 882 | return worked; |
| 872 | }; | 883 | }; |
| 873 | 884 | ||
| 874 | - CLI::Option *opt = add_option(option_name, std::move(fun), std::move(description), defaulted); | 885 | + CLI::Option *opt = add_option(option_name, std::move(fun), std::move(option_description), defaulted); |
| 875 | opt->type_name(label)->type_size(2); | 886 | opt->type_name(label)->type_size(2); |
| 876 | if(defaulted) { | 887 | if(defaulted) { |
| 877 | std::stringstream out; | 888 | std::stringstream out; |
| @@ -929,8 +940,8 @@ class App { | @@ -929,8 +940,8 @@ class App { | ||
| 929 | ///@{ | 940 | ///@{ |
| 930 | 941 | ||
| 931 | /// Add a subcommand. Inherits INHERITABLE and OptionDefaults, and help flag | 942 | /// Add a subcommand. Inherits INHERITABLE and OptionDefaults, and help flag |
| 932 | - App *add_subcommand(std::string subcommand_name = "", std::string description = "") { | ||
| 933 | - CLI::App_p subcom = std::shared_ptr<App>(new App(std::move(description), subcommand_name, this)); | 943 | + App *add_subcommand(std::string subcommand_name = "", std::string subcommand_description = "") { |
| 944 | + CLI::App_p subcom = std::shared_ptr<App>(new App(std::move(subcommand_description), subcommand_name, this)); | ||
| 934 | return add_subcommand(std::move(subcom)); | 945 | return add_subcommand(std::move(subcom)); |
| 935 | } | 946 | } |
| 936 | 947 | ||
| @@ -1278,9 +1289,9 @@ class App { | @@ -1278,9 +1289,9 @@ class App { | ||
| 1278 | /// Get the app or subcommand description | 1289 | /// Get the app or subcommand description |
| 1279 | std::string get_description() const { return description_; } | 1290 | std::string get_description() const { return description_; } |
| 1280 | 1291 | ||
| 1281 | - /// Set the description | ||
| 1282 | - App *description(const std::string &description) { | ||
| 1283 | - description_ = description; | 1292 | + /// Set the description of the app |
| 1293 | + App *description(std::string app_description) { | ||
| 1294 | + description_ = std::move(app_description); | ||
| 1284 | return this; | 1295 | return this; |
| 1285 | } | 1296 | } |
| 1286 | 1297 |
include/CLI/Option.hpp
| @@ -246,11 +246,11 @@ class Option : public OptionBase<Option> { | @@ -246,11 +246,11 @@ class Option : public OptionBase<Option> { | ||
| 246 | 246 | ||
| 247 | /// Making an option by hand is not defined, it must be made by the App class | 247 | /// Making an option by hand is not defined, it must be made by the App class |
| 248 | Option(std::string option_name, | 248 | Option(std::string option_name, |
| 249 | - std::string description, | 249 | + std::string option_description, |
| 250 | std::function<bool(results_t)> callback, | 250 | std::function<bool(results_t)> callback, |
| 251 | bool defaulted, | 251 | bool defaulted, |
| 252 | App *parent) | 252 | App *parent) |
| 253 | - : description_(std::move(description)), default_(defaulted), parent_(parent), | 253 | + : description_(std::move(option_description)), default_(defaulted), parent_(parent), |
| 254 | callback_(callback ? std::move(callback) : [](results_t) { return true; }) { | 254 | callback_(callback ? std::move(callback) : [](results_t) { return true; }) { |
| 255 | std::tie(snames_, lnames_, pname_) = detail::get_names(detail::split_names(option_name)); | 255 | std::tie(snames_, lnames_, pname_) = detail::get_names(detail::split_names(option_name)); |
| 256 | } | 256 | } |
| @@ -542,8 +542,8 @@ class Option : public OptionBase<Option> { | @@ -542,8 +542,8 @@ class Option : public OptionBase<Option> { | ||
| 542 | const std::string &get_description() const { return description_; } | 542 | const std::string &get_description() const { return description_; } |
| 543 | 543 | ||
| 544 | /// Set the description | 544 | /// Set the description |
| 545 | - Option *description(const std::string &description) { | ||
| 546 | - description_ = description; | 545 | + Option *description(std::string option_description) { |
| 546 | + description_ = std::move(option_description); | ||
| 547 | return this; | 547 | return this; |
| 548 | } | 548 | } |
| 549 | 549 |
tests/AppTest.cpp
| @@ -1847,6 +1847,21 @@ TEST_F(TApp, CustomUserSepParse2) { | @@ -1847,6 +1847,21 @@ TEST_F(TApp, CustomUserSepParse2) { | ||
| 1847 | EXPECT_EQ(vals, std::vector<int>({1, 2})); | 1847 | EXPECT_EQ(vals, std::vector<int>({1, 2})); |
| 1848 | } | 1848 | } |
| 1849 | 1849 | ||
| 1850 | +TEST_F(TApp, CustomUserSepParseFunction) { | ||
| 1851 | + | ||
| 1852 | + std::vector<int> vals = {1, 2, 3}; | ||
| 1853 | + args = {"--idx", "1,2,3"}; | ||
| 1854 | + app.add_option_function<std::vector<int>>("--idx", | ||
| 1855 | + [&vals](std::vector<int> v) { | ||
| 1856 | + vals = std::move(v); | ||
| 1857 | + return true; | ||
| 1858 | + }, | ||
| 1859 | + "", | ||
| 1860 | + ','); | ||
| 1861 | + run(); | ||
| 1862 | + EXPECT_EQ(vals, std::vector<int>({1, 2, 3})); | ||
| 1863 | +} | ||
| 1864 | + | ||
| 1850 | // #209 | 1865 | // #209 |
| 1851 | TEST_F(TApp, CustomUserSepParse3) { | 1866 | TEST_F(TApp, CustomUserSepParse3) { |
| 1852 | 1867 |