Need help with options that may or may not have a parameter value #1951
-
I have the following code that correctly outputs this usage message: I would like to be able to run it one of two ways: with arguments '-y USERNAME' and '-y=FILE USERNAME'. However '-y USERNAME' is treated as '-y=USERNAME' (which I do not want) and gives a syntax error, when instead I want it to be equivalent to '-y=blank USERNAME'. Can I have '=' be the only command separator instead of both space and '='? Or is there another solution to this? Thanks.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
This is a common problem for options that have an optional value. Your best solution may be to use the example |
Beta Was this translation helpful? Give feedback.
-
Thank you, that is the exact issue I'm running into and that example is perfect. Somehow I missed it in the documentation. I appreciate the help! |
Beta Was this translation helpful? Give feedback.
This is a common problem for options that have an optional value.
Please see this documentation on Optional Parameter Limitations in the user manual.
Your best solution may be to use the example
IParameterPreprocessor
from the user manual in your application.That preprocessor implementation customizes the parser, such that
VALUE
in--option=VALUE
is interpreted as the option parameter, and in--option VALUE
(without the=
separator),VALUE
is interpreted as the positional parameter.I believe this is exactly what you are looking for.