p-ranav / argparse

Argument Parser for Modern C++
MIT License
2.59k stars 244 forks source link

Convert default value using action() #350

Open veimmone opened 4 months ago

veimmone commented 4 months ago

If using an action() to convert the input values into custom data types, the default value poses an issue when using choices(). m_choices is a vector<string> so the default value also has to be comparable to a string, for the given value to be accepted.

This commit solves this by patching get() to convert the default value using the same action().

It is not the cleanest solution (default value has to be given as string instead of the target type), but the alternative I came up with would have changed m_choices to a typed vector which would have had wider consequences so I didn't pursue that path.