mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-03 06:34:40 +00:00
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 ```
19 lines
513 B
C++
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);
|
|
}
|