argparse/test/test_hidden_alias.cpp
Even Rouault e6e41d43c6
Add a ArgumentParser::add_hidden_alias_for() method
It is sometimes desirable to offer an alias for an argument, but without it
appearing it in the usage. For example, to phase out a deprecated wording of
an argument while not breaking backwards compatible. This can be done with
the ``ArgumentParser::add_hidden_alias_for()` method.

```cpp
argparse::ArgumentParser program("test");

auto &arg = program.add_argument("--suppress").flag();
program.add_hidden_alias_for(arg, "--supress"); // old misspelled alias
```
2024-03-12 12:08:40 +01:00

19 lines
513 B
C++

#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <doctest.hpp>
using doctest::test_suite;
TEST_CASE("Test setting a hidden alias for an argument" *
test_suite("hidden_alias")) {
argparse::ArgumentParser program("test");
auto &arg = program.add_argument("--suppress").flag();
program.add_hidden_alias_for(arg, "--supress"); // old misspelled alias
program.parse_args({"./test.exe", "--supress"});
REQUIRE(program.get<bool>("--suppress") == true);
}