Skip to content

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

Closed

Description

@lambdafu

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!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions