Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conversion error on multiple occurences of a non-vector option #39

Closed
lambdafu opened this issue Nov 18, 2017 · 0 comments
Closed

conversion error on multiple occurences of a non-vector option #39

lambdafu opened this issue Nov 18, 2017 · 0 comments

Comments

@lambdafu
Copy link
Contributor

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!

This was referenced Nov 18, 2017
This was referenced Nov 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants