You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I use a std::string as an option (say, "-o") and the option appears multiple times ("-o foo -o bar"), there is a conversion error thrown, because the lambda returns false (it checks if size of result is 1).
Some observations:
The exception messages are not very user friendly. They are too generic, not localized, etc.
The exception type is the same for all options, so it's not easy to customize the message.
Due to the simplicity of many getopt-based implementations, usually tools take the last-writer-wins strategy when options are repeated (for example, "cp -S .bak -S .orig" will choose ".orig" for backup copies).
It is possible to implement such a strategy with a custom lambda function (that's nice!), but it's extra work and not immediately obvious.
Another strategy is to always use vectors, and do the error handling / value folding post-parsing (barf!).
Simple things should be simple, and if only one "-x foo" should be allowed, then giving a diagnostics like "only one -x option allowed" should be made simple by the library. It doesn't need to be automatic, it's sufficient if I can catch the error and output an appropriate message.
In case that's not easy to do, maybe the last-writer-wins strategy for non-vectors is the better default strategy, because it can not fail by definition.
CLI11 shows some excellent design taste, and I don't want to blemish it with a specific proposal how to fix this. The main point of this ticket is to share one of the few frustrations I have with the library as a new user. Thanks!
The text was updated successfully, but these errors were encountered:
If I use a std::string as an option (say, "-o") and the option appears multiple times ("-o foo -o bar"), there is a conversion error thrown, because the lambda returns false (it checks if size of result is 1).
Some observations:
Simple things should be simple, and if only one "-x foo" should be allowed, then giving a diagnostics like "only one -x option allowed" should be made simple by the library. It doesn't need to be automatic, it's sufficient if I can catch the error and output an appropriate message.
In case that's not easy to do, maybe the last-writer-wins strategy for non-vectors is the better default strategy, because it can not fail by definition.
CLI11 shows some excellent design taste, and I don't want to blemish it with a specific proposal how to fix this. The main point of this ticket is to share one of the few frustrations I have with the library as a new user. Thanks!
The text was updated successfully, but these errors were encountered: