`permit` and `optional` don't work very well together
Closed this issue · 1 comments
pareeohnos commented
Describe the problem
If I mark an argument as optional
but I still want to validate that if a value is supplied it is correct, I would assume that I can specify the option as optional
, and also specify the permitted values. Unfortunately, if I do this and then don't supply the option, I get an error stating it is not a permitted value
Steps to reproduce the problem
argument :command do
optional
desc 'The command to run'
permit %w[run config]
end
Actual behaviour
When using this combination, I get an error
Error: unpermitted value `` for 'command' argument: choose from run, config
Expected behaviour
If I don't supply the argument, it shouldn't validate if it is permitted given I have specified it is optional
Describe your environment
- OS version: OS X 11.5
- Ruby version: 2.5.3p105
- TTY::Option version: 0.2.0
Update: I can make it work by adding nil
into the permitted list of options, but this feels a little unnecessary and hacky IMO. But this does work
argument :command do
optional
desc 'The command to run'
permit [nil, 'run', 'config']
end
piotrmurach commented
Thank you for using tty-option
and reporting this issue.
This is now fixed.