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

Refactor parameter parsing #356

Merged
merged 49 commits into from
Apr 21, 2024

Conversation

MatrixCrawler
Copy link
Collaborator

@MatrixCrawler MatrixCrawler commented Apr 3, 2024

This is my attempt in reorganizing the parameter parsing.
i extracted the different configuration parsers in single files for better overview and testing capabilities.
Here are some things i explicitly tested:

  • parsing version from
    • commandline
    • toml file
    • tfswitch file
    • terraform-version file
    • version.tf
    • terragrunt file
    • environment variable

What i did not do is adding any more parameters to the i,e, toml file.
But this should be more easily doable with the refactored code.

@MatrixCrawler MatrixCrawler force-pushed the refactor-params branch 2 times, most recently from 8c98f49 to 3acbb84 Compare April 3, 2024 12:58
@MatrixCrawler MatrixCrawler marked this pull request as draft April 3, 2024 13:05
@MatrixCrawler MatrixCrawler force-pushed the refactor-params branch 6 times, most recently from 18b9ecb to 5837518 Compare April 3, 2024 14:00
README.md Outdated Show resolved Hide resolved
lib/param_parsing/environment_test.go Outdated Show resolved Hide resolved
lib/param_parsing/parameters.go Outdated Show resolved Hide resolved
lib/param_parsing/parameters.go Outdated Show resolved Hide resolved
lib/param_parsing/parameters.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
test-data/test_precedence/terragrunt.hcl Outdated Show resolved Hide resolved
test-data/test_terragrunt_hcl/terragrunt.hcl Outdated Show resolved Hide resolved
Copy link
Collaborator

@yermulnik yermulnik left a comment

Choose a reason for hiding this comment

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

JFYI: the reason I push %q for file names and paths is that sometimes they consist of special chars (e.g. spaces or linebreaks) and wrapping them into double quotes makes it obvious where the start and the end of the string is.

README.md Outdated Show resolved Hide resolved
lib/defaults.go Outdated Show resolved Hide resolved
lib/param_parsing/terraform_version.go Outdated Show resolved Hide resolved
lib/param_parsing/terraform_version.go Outdated Show resolved Hide resolved
lib/param_parsing/terragrunt.go Outdated Show resolved Hide resolved
lib/param_parsing/versiontf.go Outdated Show resolved Hide resolved
lib/param_parsing/versiontf.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
MatrixCrawler and others added 22 commits April 21, 2024 10:15
…ng target file which would occasionally lead to errors due to existing file handler

- removed unnecessary os.Exit
- added debug logging
Co-authored-by: George L. Yermulnik <yz@yz.kiev.ua>
Co-authored-by: George L. Yermulnik <yz@yz.kiev.ua>
- refactored functions to private where possible.
- removed main_test as it was not really a useful test.
- added test for non existing file for terragrunt and .terraform-version file
- added test for non existent version in terraform
- deferred files closures
…s file would lead to showing the dropdown list which cannot be handled in an integration test, thus the test runs infinitely
@MatrixCrawler MatrixCrawler merged commit 9059ac6 into warrensbox:master Apr 21, 2024
@MatrixCrawler MatrixCrawler deleted the refactor-params branch April 21, 2024 08:20
@MatrixCrawler MatrixCrawler linked an issue Apr 22, 2024 that may be closed by this pull request
@yermulnik
Copy link
Collaborator

@MatrixCrawler I'm trying to figure out whether it's me or tfswitch — the log-level from TOML isn't being taken into account:

> fgrep log ~/.tfswitch.toml
log-level = "DEBUG"

> tfswitch --version
19:20:58.844 INFO Reading configuration from "/home/giermulnik/.tfswitch.toml"
Version: v1.1.0

> tfswitch --version -g DEBUG
19:21:06.483 INFO [toml.go:15,getParamsTOML] Reading configuration from "/home/giermulnik/.tfswitch.toml"
Version: v1.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Refactor existing code for better performance and quality
Projects
None yet
5 participants