Join GitHub today
Fixes #19574 - Validator uses options from option collector #242
In 5bf5073 Hammer introduced option sources that enable reading option values from additional providers. Default options have been turned into an option source too. Validator currently reads defaults directly. It should use option sources instead, otherwise it will prevent a command to start when required options come from some additional option source (potentially added in future).
Hold on with merging this. I just found out it breaks two tests in hammer-cli-katello. Override of
Waiting on contributor
Not yet reviewed
Nov 1, 2017
Waiting on contributor
Feb 6, 2018
Feb 22, 2018
referenced this pull request
Oct 16, 2018
The original commit that fixes #19574 wasn't compatible with most of option validations and tests in Katello that expect ID resolution to happen after the validations. To get it working I added changes allowing to place validation block between option sources #22253. It's several commits and we'll have to squash that prior to merge.
Changes in the core I made:
validate_options(:after, 'UserParams') do # ...inserts the validation block after UserParams option source end # or validate_options(:after, 'UserParams', validator: Custom::Validator.new) validate_options(:append) do # ...adds validation to the end of the queue (default behavior) end # or validate_options(:append, validator: Custom::Validator.new) # Similar to inserting output or help blocks, following modes can be used: # before, after, append, prepend, replace
The intended structure of option sources in hammer-cli-foreman is:
The default behavior always adds the block at the very end of the queue so that it validates already resolved options. If a different behavior is required, a validation can be placed before the id resolution with:
validate_options :before, 'IdResolution' do end
Changes in plugins
These are changes that have to be made in plugins after this PR is merged:
Other plugins might need changes too.
Please review the design and test the behavior. I'll work on the tests in the meantime.
@tstrachota, thanks for this PR! It works pretty well! I like the nested structure of option sources, it is quite flexible and easy to extend. As per our discussion I'd like to suggest a few changes:
Also some docs needs to be updated: