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 | 36 | if(MSVC) |
| 37 | 37 | add_definitions("/W4") |
| 38 | 38 | else() |
| 39 | - add_definitions(-Wall -Wextra -pedantic) | |
| 39 | + add_definitions(-Wall -Wextra -pedantic -Wshadow) | |
| 40 | 40 | endif() |
| 41 | 41 | |
| 42 | 42 | if(CMAKE_VERSION VERSION_GREATER 3.6) | ... | ... |
include/CLI/App.hpp
| ... | ... | @@ -193,8 +193,8 @@ class App { |
| 193 | 193 | ///@} |
| 194 | 194 | |
| 195 | 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 | 198 | // Inherit if not from a nullptr |
| 199 | 199 | if(parent_ != nullptr) { |
| 200 | 200 | if(parent_->help_ptr_ != nullptr) |
| ... | ... | @@ -228,7 +228,8 @@ class App { |
| 228 | 228 | ///@{ |
| 229 | 229 | |
| 230 | 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 | 233 | set_help_flag("-h,--help", "Print this help message and exit"); |
| 233 | 234 | } |
| 234 | 235 | |
| ... | ... | @@ -353,16 +354,16 @@ class App { |
| 353 | 354 | /// |
| 354 | 355 | Option *add_option(std::string option_name, |
| 355 | 356 | callback_t option_callback, |
| 356 | - std::string description = "", | |
| 357 | + std::string option_description = "", | |
| 357 | 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 | 361 | if(std::find_if(std::begin(options_), std::end(options_), [&myopt](const Option_p &v) { |
| 361 | 362 | return *v == myopt; |
| 362 | 363 | }) == std::end(options_)) { |
| 363 | 364 | options_.emplace_back(); |
| 364 | 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 | 367 | option_defaults_.copy_to(option.get()); |
| 367 | 368 | return option.get(); |
| 368 | 369 | } else |
| ... | ... | @@ -373,11 +374,11 @@ class App { |
| 373 | 374 | template <typename T, enable_if_t<!is_vector<T>::value, detail::enabler> = detail::dummy> |
| 374 | 375 | Option *add_option(std::string option_name, |
| 375 | 376 | T &variable, ///< The variable to set |
| 376 | - std::string description = "") { | |
| 377 | + std::string option_description = "") { | |
| 377 | 378 | |
| 378 | 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 | 382 | opt->type_name(detail::type_name<T>()); |
| 382 | 383 | return opt; |
| 383 | 384 | } |
| ... | ... | @@ -386,7 +387,7 @@ class App { |
| 386 | 387 | template <typename T, enable_if_t<!is_vector<T>::value, detail::enabler> = detail::dummy> |
| 387 | 388 | Option *add_option_function(std::string option_name, |
| 388 | 389 | const std::function<bool(const T &)> &func, ///< the callback to execute |
| 389 | - std::string description = "") { | |
| 390 | + std::string option_description = "") { | |
| 390 | 391 | |
| 391 | 392 | CLI::callback_t fun = [func](CLI::results_t res) { |
| 392 | 393 | T variable; |
| ... | ... | @@ -397,7 +398,7 @@ class App { |
| 397 | 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 | 402 | opt->type_name(detail::type_name<T>()); |
| 402 | 403 | return opt; |
| 403 | 404 | } |
| ... | ... | @@ -406,12 +407,12 @@ class App { |
| 406 | 407 | template <typename T, enable_if_t<!is_vector<T>::value, detail::enabler> = detail::dummy> |
| 407 | 408 | Option *add_option(std::string option_name, |
| 408 | 409 | T &variable, ///< The variable to set |
| 409 | - std::string description, | |
| 410 | + std::string option_description, | |
| 410 | 411 | bool defaulted) { |
| 411 | 412 | |
| 412 | 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 | 416 | opt->type_name(detail::type_name<T>()); |
| 416 | 417 | if(defaulted) { |
| 417 | 418 | std::stringstream out; |
| ... | ... | @@ -425,14 +426,14 @@ class App { |
| 425 | 426 | template <typename T> |
| 426 | 427 | Option *add_option(std::string option_name, |
| 427 | 428 | std::vector<T> &variable, ///< The variable vector to set |
| 428 | - std::string description = "", | |
| 429 | + std::string option_description = "", | |
| 429 | 430 | char delimiter = '\0') { |
| 430 | 431 | |
| 431 | 432 | CLI::callback_t fun = [&variable, delimiter](CLI::results_t res) { |
| 432 | 433 | bool retval = true; |
| 433 | 434 | variable.clear(); |
| 434 | 435 | for(const auto &elem : res) { |
| 435 | - if(delimiter != '\0') { | |
| 436 | + if((delimiter != '\0') && (elem.find_first_of(delimiter) != std::string::npos)) { | |
| 436 | 437 | for(const auto &var : CLI::detail::split(elem, delimiter)) { |
| 437 | 438 | if(!var.empty()) { |
| 438 | 439 | variable.emplace_back(); |
| ... | ... | @@ -447,7 +448,7 @@ class App { |
| 447 | 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 | 452 | opt->type_name(detail::type_name<T>())->type_size(-1); |
| 452 | 453 | return opt; |
| 453 | 454 | } |
| ... | ... | @@ -456,7 +457,7 @@ class App { |
| 456 | 457 | template <typename T> |
| 457 | 458 | Option *add_option(std::string option_name, |
| 458 | 459 | std::vector<T> &variable, ///< The variable vector to set |
| 459 | - std::string description, | |
| 460 | + std::string option_description, | |
| 460 | 461 | bool defaulted, |
| 461 | 462 | char delimiter = '\0') { |
| 462 | 463 | |
| ... | ... | @@ -464,7 +465,7 @@ class App { |
| 464 | 465 | bool retval = true; |
| 465 | 466 | variable.clear(); |
| 466 | 467 | for(const auto &elem : res) { |
| 467 | - if(delimiter != '\0') { | |
| 468 | + if((delimiter != '\0') && (elem.find_first_of(delimiter) != std::string::npos)) { | |
| 468 | 469 | for(const auto &var : CLI::detail::split(elem, delimiter)) { |
| 469 | 470 | if(!var.empty()) { |
| 470 | 471 | variable.emplace_back(); |
| ... | ... | @@ -479,7 +480,7 @@ class App { |
| 479 | 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 | 484 | opt->type_name(detail::type_name<T>())->type_size(-1); |
| 484 | 485 | if(defaulted) |
| 485 | 486 | opt->default_str("[" + detail::join(variable) + "]"); |
| ... | ... | @@ -490,15 +491,25 @@ class App { |
| 490 | 491 | template <typename T, enable_if_t<is_vector<T>::value, detail::enabler> = detail::dummy> |
| 491 | 492 | Option *add_option_function(std::string option_name, |
| 492 | 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 | 498 | T values; |
| 497 | 499 | bool retval = true; |
| 498 | 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 | 514 | if(retval) { |
| 504 | 515 | return func(values); |
| ... | ... | @@ -506,13 +517,13 @@ class App { |
| 506 | 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 | 521 | opt->type_name(detail::type_name<T>())->type_size(-1); |
| 511 | 522 | return opt; |
| 512 | 523 | } |
| 513 | 524 | |
| 514 | 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 | 527 | if(help_ptr_ != nullptr) { |
| 517 | 528 | remove_option(help_ptr_); |
| 518 | 529 | help_ptr_ = nullptr; |
| ... | ... | @@ -520,7 +531,7 @@ class App { |
| 520 | 531 | |
| 521 | 532 | // Empty name will simply remove the help flag |
| 522 | 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 | 535 | help_ptr_->configurable(false); |
| 525 | 536 | } |
| 526 | 537 | |
| ... | ... | @@ -528,7 +539,7 @@ class App { |
| 528 | 539 | } |
| 529 | 540 | |
| 530 | 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 | 543 | if(help_all_ptr_ != nullptr) { |
| 533 | 544 | remove_option(help_all_ptr_); |
| 534 | 545 | help_all_ptr_ = nullptr; |
| ... | ... | @@ -536,7 +547,7 @@ class App { |
| 536 | 547 | |
| 537 | 548 | // Empty name will simply remove the help all flag |
| 538 | 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 | 551 | help_all_ptr_->configurable(false); |
| 541 | 552 | } |
| 542 | 553 | |
| ... | ... | @@ -544,9 +555,9 @@ class App { |
| 544 | 555 | } |
| 545 | 556 | |
| 546 | 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 | 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 | 561 | if(opt->get_positional()) |
| 551 | 562 | throw IncorrectConstruction::PositionalFlag(flag_name); |
| 552 | 563 | opt->type_size(0); |
| ... | ... | @@ -558,7 +569,7 @@ class App { |
| 558 | 569 | enable_if_t<std::is_integral<T>::value && !is_bool<T>::value, detail::enabler> = detail::dummy> |
| 559 | 570 | Option *add_flag(std::string flag_name, |
| 560 | 571 | T &flag_count, ///< A variable holding the count |
| 561 | - std::string description = "") { | |
| 572 | + std::string flag_description = "") { | |
| 562 | 573 | flag_count = 0; |
| 563 | 574 | Option *opt; |
| 564 | 575 | CLI::callback_t fun = [&flag_count](CLI::results_t res) { |
| ... | ... | @@ -568,10 +579,10 @@ class App { |
| 568 | 579 | if(detail::has_false_flags(flag_name)) { |
| 569 | 580 | std::vector<std::string> neg = detail::get_false_flags(flag_name); |
| 570 | 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 | 583 | opt->fnames_ = std::move(neg); |
| 573 | 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 | 588 | if(opt->get_positional()) |
| ... | ... | @@ -585,7 +596,7 @@ class App { |
| 585 | 596 | template <typename T, enable_if_t<is_bool<T>::value, detail::enabler> = detail::dummy> |
| 586 | 597 | Option *add_flag(std::string flag_name, |
| 587 | 598 | T &flag_result, ///< A variable holding true if passed |
| 588 | - std::string description = "") { | |
| 599 | + std::string flag_description = "") { | |
| 589 | 600 | flag_result = false; |
| 590 | 601 | Option *opt; |
| 591 | 602 | CLI::callback_t fun = [&flag_result](CLI::results_t res) { |
| ... | ... | @@ -595,10 +606,10 @@ class App { |
| 595 | 606 | if(detail::has_false_flags(flag_name)) { |
| 596 | 607 | std::vector<std::string> neg = detail::get_false_flags(flag_name); |
| 597 | 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 | 610 | opt->fnames_ = std::move(neg); |
| 600 | 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 | 615 | if(opt->get_positional()) |
| ... | ... | @@ -611,7 +622,7 @@ class App { |
| 611 | 622 | /// Add option for callback |
| 612 | 623 | Option *add_flag_function(std::string flag_name, |
| 613 | 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 | 627 | CLI::callback_t fun = [function](CLI::results_t res) { |
| 617 | 628 | int flag_count = 0; |
| ... | ... | @@ -623,10 +634,10 @@ class App { |
| 623 | 634 | if(detail::has_false_flags(flag_name)) { |
| 624 | 635 | std::vector<std::string> neg = detail::get_false_flags(flag_name); |
| 625 | 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 | 638 | opt->fnames_ = std::move(neg); |
| 628 | 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 | 643 | if(opt->get_positional()) |
| ... | ... | @@ -639,8 +650,8 @@ class App { |
| 639 | 650 | /// Add option for callback (C++14 or better only) |
| 640 | 651 | Option *add_flag(std::string flag_name, |
| 641 | 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 | 656 | #endif |
| 646 | 657 | |
| ... | ... | @@ -649,21 +660,21 @@ class App { |
| 649 | 660 | Option *add_set(std::string option_name, |
| 650 | 661 | T &member, ///< The selected member of the set |
| 651 | 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 | 666 | opt->check(IsMember{options}); |
| 656 | 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 | 671 | template <typename T> |
| 661 | 672 | Option *add_mutable_set(std::string option_name, |
| 662 | 673 | T &member, ///< The selected member of the set |
| 663 | 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 | 678 | opt->check(IsMember{&options}); |
| 668 | 679 | return opt; |
| 669 | 680 | } |
| ... | ... | @@ -673,10 +684,10 @@ class App { |
| 673 | 684 | Option *add_set(std::string option_name, |
| 674 | 685 | T &member, ///< The selected member of the set |
| 675 | 686 | std::set<T> options, ///< The set of possibilities |
| 676 | - std::string description, | |
| 687 | + std::string option_description, | |
| 677 | 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 | 691 | opt->check(IsMember{options}); |
| 681 | 692 | return opt; |
| 682 | 693 | } |
| ... | ... | @@ -686,10 +697,10 @@ class App { |
| 686 | 697 | Option *add_mutable_set(std::string option_name, |
| 687 | 698 | T &member, ///< The selected member of the set |
| 688 | 699 | const std::set<T> &options, ///< The set of possibilities |
| 689 | - std::string description, | |
| 700 | + std::string option_description, | |
| 690 | 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 | 704 | opt->check(IsMember{&options}); |
| 694 | 705 | return opt; |
| 695 | 706 | } |
| ... | ... | @@ -699,9 +710,9 @@ class App { |
| 699 | 710 | Option *add_set_ignore_case(std::string option_name, |
| 700 | 711 | std::string &member, ///< The selected member of the set |
| 701 | 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 | 716 | opt->transform(IsMember{options, CLI::ignore_case}); |
| 706 | 717 | return opt; |
| 707 | 718 | } |
| ... | ... | @@ -712,9 +723,9 @@ class App { |
| 712 | 723 | Option *add_mutable_set_ignore_case(std::string option_name, |
| 713 | 724 | std::string &member, ///< The selected member of the set |
| 714 | 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 | 729 | opt->transform(IsMember{&options, CLI::ignore_case}); |
| 719 | 730 | return opt; |
| 720 | 731 | } |
| ... | ... | @@ -724,10 +735,10 @@ class App { |
| 724 | 735 | Option *add_set_ignore_case(std::string option_name, |
| 725 | 736 | std::string &member, ///< The selected member of the set |
| 726 | 737 | std::set<std::string> options, ///< The set of possibilities |
| 727 | - std::string description, | |
| 738 | + std::string option_description, | |
| 728 | 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 | 742 | opt->transform(IsMember{options, CLI::ignore_case}); |
| 732 | 743 | return opt; |
| 733 | 744 | } |
| ... | ... | @@ -738,10 +749,10 @@ class App { |
| 738 | 749 | Option *add_mutable_set_ignore_case(std::string option_name, |
| 739 | 750 | std::string &member, ///< The selected member of the set |
| 740 | 751 | const std::set<std::string> &options, ///< The set of possibilities |
| 741 | - std::string description, | |
| 752 | + std::string option_description, | |
| 742 | 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 | 756 | opt->transform(IsMember{&options, CLI::ignore_case}); |
| 746 | 757 | return opt; |
| 747 | 758 | } |
| ... | ... | @@ -751,9 +762,9 @@ class App { |
| 751 | 762 | Option *add_set_ignore_underscore(std::string option_name, |
| 752 | 763 | std::string &member, ///< The selected member of the set |
| 753 | 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 | 768 | opt->transform(IsMember{options, CLI::ignore_underscore}); |
| 758 | 769 | return opt; |
| 759 | 770 | } |
| ... | ... | @@ -764,9 +775,9 @@ class App { |
| 764 | 775 | Option *add_mutable_set_ignore_underscore(std::string option_name, |
| 765 | 776 | std::string &member, ///< The selected member of the set |
| 766 | 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 | 781 | opt->transform(IsMember{options, CLI::ignore_underscore}); |
| 771 | 782 | return opt; |
| 772 | 783 | } |
| ... | ... | @@ -776,10 +787,10 @@ class App { |
| 776 | 787 | Option *add_set_ignore_underscore(std::string option_name, |
| 777 | 788 | std::string &member, ///< The selected member of the set |
| 778 | 789 | std::set<std::string> options, ///< The set of possibilities |
| 779 | - std::string description, | |
| 790 | + std::string option_description, | |
| 780 | 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 | 794 | opt->transform(IsMember{options, CLI::ignore_underscore}); |
| 784 | 795 | return opt; |
| 785 | 796 | } |
| ... | ... | @@ -790,10 +801,10 @@ class App { |
| 790 | 801 | Option *add_mutable_set_ignore_underscore(std::string option_name, |
| 791 | 802 | std::string &member, ///< The selected member of the set |
| 792 | 803 | const std::set<std::string> &options, ///< The set of possibilities |
| 793 | - std::string description, | |
| 804 | + std::string option_description, | |
| 794 | 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 | 808 | opt->transform(IsMember{&options, CLI::ignore_underscore}); |
| 798 | 809 | return opt; |
| 799 | 810 | } |
| ... | ... | @@ -803,9 +814,9 @@ class App { |
| 803 | 814 | Option *add_set_ignore_case_underscore(std::string option_name, |
| 804 | 815 | std::string &member, ///< The selected member of the set |
| 805 | 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 | 820 | opt->transform(IsMember{options, CLI::ignore_underscore, CLI::ignore_case}); |
| 810 | 821 | return opt; |
| 811 | 822 | } |
| ... | ... | @@ -817,9 +828,9 @@ class App { |
| 817 | 828 | Option *add_mutable_set_ignore_case_underscore(std::string option_name, |
| 818 | 829 | std::string &member, ///< The selected member of the set |
| 819 | 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 | 834 | opt->transform(IsMember{&options, CLI::ignore_underscore, CLI::ignore_case}); |
| 824 | 835 | return opt; |
| 825 | 836 | } |
| ... | ... | @@ -829,10 +840,10 @@ class App { |
| 829 | 840 | Option *add_set_ignore_case_underscore(std::string option_name, |
| 830 | 841 | std::string &member, ///< The selected member of the set |
| 831 | 842 | std::set<std::string> options, ///< The set of possibilities |
| 832 | - std::string description, | |
| 843 | + std::string option_description, | |
| 833 | 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 | 847 | opt->transform(IsMember{options, CLI::ignore_underscore, CLI::ignore_case}); |
| 837 | 848 | return opt; |
| 838 | 849 | } |
| ... | ... | @@ -844,10 +855,10 @@ class App { |
| 844 | 855 | Option *add_mutable_set_ignore_case_underscore(std::string option_name, |
| 845 | 856 | std::string &member, ///< The selected member of the set |
| 846 | 857 | const std::set<std::string> &options, ///< The set of possibilities |
| 847 | - std::string description, | |
| 858 | + std::string option_description, | |
| 848 | 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 | 862 | opt->transform(IsMember{&options, CLI::ignore_underscore, CLI::ignore_case}); |
| 852 | 863 | return opt; |
| 853 | 864 | } |
| ... | ... | @@ -856,7 +867,7 @@ class App { |
| 856 | 867 | template <typename T> |
| 857 | 868 | Option *add_complex(std::string option_name, |
| 858 | 869 | T &variable, |
| 859 | - std::string description = "", | |
| 870 | + std::string option_description = "", | |
| 860 | 871 | bool defaulted = false, |
| 861 | 872 | std::string label = "COMPLEX") { |
| 862 | 873 | |
| ... | ... | @@ -871,7 +882,7 @@ class App { |
| 871 | 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 | 886 | opt->type_name(label)->type_size(2); |
| 876 | 887 | if(defaulted) { |
| 877 | 888 | std::stringstream out; |
| ... | ... | @@ -929,8 +940,8 @@ class App { |
| 929 | 940 | ///@{ |
| 930 | 941 | |
| 931 | 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 | 945 | return add_subcommand(std::move(subcom)); |
| 935 | 946 | } |
| 936 | 947 | |
| ... | ... | @@ -1278,9 +1289,9 @@ class App { |
| 1278 | 1289 | /// Get the app or subcommand description |
| 1279 | 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 | 1295 | return this; |
| 1285 | 1296 | } |
| 1286 | 1297 | ... | ... |
include/CLI/Option.hpp
| ... | ... | @@ -246,11 +246,11 @@ class Option : public OptionBase<Option> { |
| 246 | 246 | |
| 247 | 247 | /// Making an option by hand is not defined, it must be made by the App class |
| 248 | 248 | Option(std::string option_name, |
| 249 | - std::string description, | |
| 249 | + std::string option_description, | |
| 250 | 250 | std::function<bool(results_t)> callback, |
| 251 | 251 | bool defaulted, |
| 252 | 252 | App *parent) |
| 253 | - : description_(std::move(description)), default_(defaulted), parent_(parent), | |
| 253 | + : description_(std::move(option_description)), default_(defaulted), parent_(parent), | |
| 254 | 254 | callback_(callback ? std::move(callback) : [](results_t) { return true; }) { |
| 255 | 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 | 542 | const std::string &get_description() const { return description_; } |
| 543 | 543 | |
| 544 | 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 | 547 | return this; |
| 548 | 548 | } |
| 549 | 549 | ... | ... |
tests/AppTest.cpp
| ... | ... | @@ -1847,6 +1847,21 @@ TEST_F(TApp, CustomUserSepParse2) { |
| 1847 | 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 | 1865 | // #209 |
| 1851 | 1866 | TEST_F(TApp, CustomUserSepParse3) { |
| 1852 | 1867 | ... | ... |