But if we use the store_into feature, it is incompatible with required. Namely, it cannot recognize that an argument was passed and stored into the specified variable.
clang++ -I argparse/include/ example.cc -o example
for a1 in " " "--threads " "--threads 2 "; do
for a2 in " " "--boxes " "--boxes 3 "; do
echo ./example $a1 $a2
./example $a1 $a2
done
done
Output (edited for clarity):
# This works (falls back to default values):
./example
got num_threads = 1 num_boxes = 1
# This raises an exception, as it should
./example --boxes
--boxes: no value provided.
# This also works:
./example --boxes 3
got num_threads = 1 num_boxes = 3
# This raises an exception, as it should
./example --threads
--threads: no value provided.
# This raises an exception, as it should
./example --threads --boxes
--boxes: no value provided.
# This raises an exception, as it should
./example --threads --boxes 3
--threads: no value provided.
# This fails, raising an exception even though `--threads` has a value.
./example --threads 2
--threads: no value provided.
# This raises an exception, as it should
./example --threads 2 --boxes
--boxes: no value provided.
# This fails, raising an exception even though `--threads` has a value.
./example --threads 2 --boxes 3
--threads: no value provided.
Previously in https://github.com/p-ranav/argparse/pull/33 a helpful feature
required()
was added with these rules:But if we use the
store_into
feature, it is incompatible withrequired
. Namely, it cannot recognize that an argument was passed and stored into the specified variable.MWE:
Test script:
Output (edited for clarity):