Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Refactor environment parsing #534

Merged
merged 13 commits into from
Sep 9, 2019

Conversation

EverlastingBugstopper
Copy link
Contributor

@EverlastingBugstopper EverlastingBugstopper commented Sep 6, 2019

This PR changes a lot of my bad Rust code into slightly better Rust code. The main goal here is readability.

src/settings/project/mod.rs Show resolved Hide resolved
src/settings/project/mod.rs Outdated Show resolved Hide resolved
src/settings/project/mod.rs Outdated Show resolved Hide resolved
src/settings/project/mod.rs Outdated Show resolved Hide resolved
emoji::WARN
);

// TODO: deprecate --release, remove warnings and parsing
// switch wrangler publish behavior to act the same at top level
// and environments
// brace yourself, this is hairy
let workers_dot_dev = match environment {
let workers_dot_dev: bool = match environment {
Copy link
Contributor

Choose a reason for hiding this comment

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

Part of me wonders if there is a way to further simplify the logic around the truth table for workers_dot_dev, release, and route. What we have here is totally serviceable--I think, however, this logic could become even more understandable for folks if we reduced the nested matches and focused on easy-to-follow compound conditionals.

For example, we could use logic that could do the following pseudocode:

  1. Extract a specified environment only once using one match statement.
  2. If environment does not exist (is None, so top level configs used):
    a. If release == true and workers_dot_dev.is_some(), throw error message stating conflict between using --release and workers_dot_dev.
    b. If release == true and workers_dot_dev.is_none(), warn of deprecation and return false (proceed to deploy to route)
    c. If release == false and self.workers_dot_dev.is_some() and !self.route.is_empty(), bail with wdd_failure
    d. If release == false and self.workers_dot_dev.is_some() and self.route.is_empty(), return workers_dot_dev value
    e. If release == false and self.workers_dot_dev.is_none() return true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll work on this today :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, can we leave this so we can merge refactor today? @gabbifish

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense to me! I'll save the link to this convo and we can revisit it after this is merged.

src/settings/project/mod.rs Show resolved Hide resolved
src/settings/project/mod.rs Show resolved Hide resolved
if environment.zone_id.is_some() {
target.zone_id = environment.zone_id.clone();
}
target.kv_namespaces = environment.kv_namespaces.clone();
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to wrap environment.kv_namespaces in the same conditionals as above? I would think kv inheritance would work the same as other toml fields...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ashleymichal and I talked about this and said that it doesn't really make sense to inherit kv namespaces because it's an anti-pattern to use multiple namespaces across different environments. I don't want my staging worker to use my production kv namespaces. In this case - if you wanted to use the same namespace for both, you would just have to copy + paste to explicitly use the same namespaces for both environments. Open to discussion about this.

Copy link
Contributor

@gabbifish gabbifish Sep 9, 2019

Choose a reason for hiding this comment

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

This makes sense. It could be worth adding this as a comment to clarify why this logic diverges from the rest of the logic preceding it. Other than that, LGTM + I will approve this!

@EverlastingBugstopper EverlastingBugstopper changed the title [WIP] Refactor environment parsing Refactor environment parsing Sep 9, 2019
Copy link
Contributor

@gabbifish gabbifish left a comment

Choose a reason for hiding this comment

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

LGTM (assuming we are doing the further cleanup/refactoring in a consequent PR) :D

@EverlastingBugstopper EverlastingBugstopper merged commit 3be7e05 into avery/environments Sep 9, 2019
@delete-merged-branch delete-merged-branch bot deleted the avery/environments-refactor branch September 9, 2019 19:38
@gabbifish gabbifish mentioned this pull request Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants