File: retired.cpp

package info (click to toggle)
cli11 2.4.1%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 2,120 kB
  • sloc: cpp: 23,299; python: 129; sh: 64; makefile: 11; ruby: 7
file content (46 lines) | stat: -rw-r--r-- 1,477 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) 2017-2024, University of Cincinnati, developed by Henry Schreiner
// under NSF AWARD 1414736 and by the respective contributors.
// All rights reserved.
//
// SPDX-License-Identifier: BSD-3-Clause

#include <CLI/CLI.hpp>
#include <iostream>
#include <utility>
#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;
}