Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration validation #709

Merged
merged 1 commit into from
Jan 18, 2022
Merged

Add configuration validation #709

merged 1 commit into from
Jan 18, 2022

Conversation

paracycle
Copy link
Member

Motivation

Fixes #704

Implementation

The first time options method is hit, we validate the Tapioca configuration. The validation makes sure that all top level keys match to some command, all command options match to one of the flags for that command and that all values for command options are of the expected type.

Tests

Add new tests for configuration failures.

@paracycle paracycle requested a review from a team January 17, 2022 23:07
@paracycle paracycle self-assigned this Jan 17, 2022
@paracycle paracycle added the enhancement New feature or request label Jan 17, 2022
lib/tapioca/helpers/config_helper.rb Outdated Show resolved Hide resolved
lib/tapioca/helpers/config_helper.rb Show resolved Hide resolved
lib/tapioca/helpers/config_helper.rb Show resolved Hide resolved
The first time `options` method is hit, we validate the Tapioca
configuration. The validation makes sure that all top level keys match
to some command, all command options match to one of the flags for that
command and that all values for command options are of the expected
type.
Thor::CoreExt::HashWithIndifferentAccess.new(config[command_name] || {})
end

sig { params(config_file: String, config: T::Hash[T.untyped, T.untyped]).void }
def validate_config!(config_file, config)
# To ensure that this is not re-entered, we mark during validation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we expect config_options to be called more than once in the same execution?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, say_error (or say) end up calling options[:quiet] to decide to print or not which ends up reentering the options method, before we've memoized the merged options hash. That causes an infinite loop. In general, any Thor code we call from this method could end up doing another options lookup, so I am protecting this method.

@paracycle paracycle merged commit 5a93e66 into main Jan 18, 2022
@paracycle paracycle deleted the uk-validate-config branch January 18, 2022 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tapioca should check its config file
4 participants