mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-29 12:13:52 +00:00
* add ability to specify deprecated or retired options. * add retired example and tests * update some formatting and a few more test executions * fix formatting on retired.cpp * add another test to fill coverage gap for existing options that are being retired. * add example comments * Update readme with the descriptions of the new helper functions * fix space on readme * Apply suggestions from code review Co-Authored-By: Christoph Bachhuber <cbachhuber89@gmail.com> * add some flags to the code coverage report and update some names and add more descriptions to deprecated options * update formatting on App
39 lines
1.2 KiB
C++
39 lines
1.2 KiB
C++
#include "CLI/CLI.hpp"
|
|
#include <vector>
|
|
|
|
// This example shows the usage of the retired and deprecated option helper methods
|
|
int main(int argc, char **argv) {
|
|
|
|
CLI::App app("example for retired/deprecated options");
|
|
std::vector<int> x;
|
|
auto opt1 = app.add_option("--retired_option2", x);
|
|
|
|
std::pair<int, int> y;
|
|
auto opt2 = app.add_option("--deprecate", y);
|
|
|
|
app.add_option("--not_deprecated", x);
|
|
|
|
// specify that a non-existing option is retired
|
|
CLI::retire_option(app, "--retired_option");
|
|
|
|
// specify that an existing option is retired and non-functional: this will replace the option with another that
|
|
// behaves the same but does nothing
|
|
CLI::retire_option(app, opt1);
|
|
|
|
// deprecate an existing option and specify the recommended replacement
|
|
CLI::deprecate_option(opt2, "--not_deprecated");
|
|
|
|
CLI11_PARSE(app, argc, argv);
|
|
|
|
if(!x.empty()) {
|
|
std::cout << "Retired option example: got --not_deprecated values:";
|
|
for(auto &xval : x) {
|
|
std::cout << xval << " ";
|
|
}
|
|
std::cout << '\n';
|
|
} else if(app.count_all() == 1) {
|
|
std::cout << "Retired option example: no arguments received\n";
|
|
}
|
|
return 0;
|
|
}
|