From e44023f424c16a0136238624222b2e9a0b33b9b6 Mon Sep 17 00:00:00 2001 From: Yoshihiro Hokazono Date: Wed, 22 Jun 2022 07:55:48 +0900 Subject: [PATCH] Explain variable-length arguments in README --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index a318b005..e63a8149 100644 --- a/README.md +++ b/README.md @@ -402,6 +402,29 @@ catch (const std::runtime_error& err) { auto query_point = program.get>("--query_point"); // {3.5, 4.7, 9.2} ``` +You can also make a variable length list of arguments with the ```.nargs```. +Below are some examples. + +```cpp +program.add_argument("--input_files") + .nargs(1, 3); // This accepts 1 to 3 arguments. +``` + +Some useful patterns are defined like "?", "*", "+" of argparse in Python. + +```cpp +program.add_argument("--input_files") + .nargs(argparse::nargs_pattern::any); // "*" in Python. This accepts any number of arguments including 0. +``` +```cpp +program.add_argument("--input_files") + .nargs(argparse::nargs_pattern::at_least_one); // "+" in Python. This accepts one or more number of arguments. +``` +```cpp +program.add_argument("--input_files") + .nargs(argparse::nargs_pattern::zero_or_one); // "?" in Python. This accepts an argument optionally. +``` + ### Compound Arguments Compound arguments are optional arguments that are combined and provided as a single argument. Example: ```ps -aux```