mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-03 14:44:40 +00:00
It is possible to bind arguments to a variable storing their value, as an alternative to explicitly calling ``program.get<T>(arg_name)`` or ``program[arg_name]`` This is currently implementeted for variables of type ``bool`` (this also implicitly calls ``flag()``), ``int``, ``double``, ``std::string`` and ``std::vector<std::string>``. If the argument is not specified in the command line, the default value (if set) is set into the variable. ```cpp bool flagvar = false; program.add_argument("--flagvar").store_into(flagvar); int intvar = 0; program.add_argument("--intvar").store_into(intvar); double doublevar = 0; program.add_argument("--doublevar").store_into(doublevar); std::string strvar; program.add_argument("--strvar").store_into(strvar); std::vector<std::string> strvar_repeated; program.add_argument("--strvar-repeated").append().store_into(strvar_repeated); std::vector<std::string> strvar_multi_valued; program.add_argument("--strvar-multi-valued").nargs(2).store_into(strvar_multi_valued); ``` |
||
---|---|---|
.. | ||
.gitignore | ||
argparse_details.cppm | ||
CMakeLists.txt | ||
doctest.hpp | ||
main.cpp | ||
README.md | ||
test_actions.cpp | ||
test_append.cpp | ||
test_as_container.cpp | ||
test_bool_operator.cpp | ||
test_choices.cpp | ||
test_compound_arguments.cpp | ||
test_container_arguments.cpp | ||
test_default_args.cpp | ||
test_default_value.cpp | ||
test_equals_form.cpp | ||
test_error_reporting.cpp | ||
test_get.cpp | ||
test_help.cpp | ||
test_invalid_arguments.cpp | ||
test_is_used.cpp | ||
test_issue_37.cpp | ||
test_mutually_exclusive_group.cpp | ||
test_negative_numbers.cpp | ||
test_optional_arguments.cpp | ||
test_parent_parsers.cpp | ||
test_parse_args.cpp | ||
test_parse_known_args.cpp | ||
test_positional_arguments.cpp | ||
test_prefix_chars.cpp | ||
test_repr.cpp | ||
test_required_arguments.cpp | ||
test_scan.cpp | ||
test_store_into.cpp | ||
test_stringstream.cpp | ||
test_subparsers.cpp | ||
test_utility.hpp | ||
test_version.cpp |
Argparse Tests
Linux
$ mkdir build
$ cd build
$ cmake ../.
$ make
$ ./tests
Windows
- Generate Visual Studio solution
$ mkdir build
$ cd build
$ cmake ../. -G "Visual Studio 15 2017"
- Open ARGPARSE.sln
- Build tests in RELEASE | x64
- Run tests.exe