docopt.cpp icon indicating copy to clipboard operation
docopt.cpp copied to clipboard

Define validation or possible values for the value of an option

Open isometriq opened this issue 8 years ago • 5 comments

Fiven the following usage string:

Usage:
  vrplayer-openvr [--option VALUE]

Options:
  --option VALUE  Set of options (first|second|third) [default: first]

Is it possible to validate a set of options (see the values in the parenthesis.

Could it be written also as:

  --option VALUE  Set of options [values: first|second|third, default: first]

If not possible, then its a feature request.

isometriq avatar Sep 12 '17 21:09 isometriq

What is expected is that the parser also restrict the used option value (and throws if invalid). In the my example, I have a pipe list, but actually could it be a regex?

isometriq avatar Sep 12 '17 21:09 isometriq

Any comment on this?

Related: https://github.com/docopt/docopt/issues/45

piotr-dobrogost avatar Sep 24 '18 12:09 piotr-dobrogost

No, the syntax doesn't have any way to do this .. it would be up to you to provide that kind of validation when you look at the values you get. I think trying to adjust the syntax would be tricky to do.

jaredgrubb avatar Sep 24 '18 19:09 jaredgrubb

What about syntax proposed above by @isometriq ? --option VALUE Description… [values: first|second|third, default: first]

piotr-dobrogost avatar Sep 26 '18 09:09 piotr-dobrogost

Looking in the man pages for git, I think a better syntax would be:

--diff-algorithm={patience|minimal|histogram|myers}

I think this could be a nice addition, however this library tries to conform to the "standard" put forth by the peer project and original "Docopt" in Python. So before I could adopt this, it would need to be proposed and implemented in the original.

jaredgrubb avatar Sep 26 '18 15:09 jaredgrubb