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
Merged
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
c5a54ad
- extract params into own struct for better usability
MatrixCrawler Apr 2, 2024
0462a64
Apply suggestions from code review
MatrixCrawler Apr 3, 2024
67b96c9
- implement suggestions from review
MatrixCrawler Apr 3, 2024
007dd1b
- explicitly create viper parser
MatrixCrawler Apr 3, 2024
04fa46b
- update test files
MatrixCrawler Apr 3, 2024
c9f8028
Apply suggestions from code review
MatrixCrawler Apr 4, 2024
f2faf5f
- try to use terragrunt parser
MatrixCrawler Apr 4, 2024
9e61257
Revert "- try to use terragrunt parser"
MatrixCrawler Apr 4, 2024
b248c9e
- rebase
MatrixCrawler Apr 5, 2024
4339565
- adapt to logging
MatrixCrawler Apr 5, 2024
f79fa5b
- move defaults
MatrixCrawler Apr 5, 2024
3eb7618
Apply suggestions from code review
MatrixCrawler Apr 5, 2024
687b9ec
Apply suggestions from code review
MatrixCrawler Apr 5, 2024
9d5d479
- apply suggested changes
MatrixCrawler Apr 5, 2024
763c30a
- apply suggested changes
MatrixCrawler Apr 5, 2024
ec776ab
- remove unnecessary logging
MatrixCrawler Apr 5, 2024
32f7185
- rebased and updated vulnerable dependencies
MatrixCrawler Apr 5, 2024
2af831f
- update dependencies
MatrixCrawler Apr 5, 2024
02b03ff
- fix parameters for DownloadFromURL
MatrixCrawler Apr 5, 2024
c5c1cd9
- remove fatal loggings from tests. Relates to #363
MatrixCrawler Apr 7, 2024
64ee48c
- make logger exit on fatal
MatrixCrawler Apr 7, 2024
c3659d8
- rebasing
MatrixCrawler Apr 8, 2024
06e7817
- fix logging
MatrixCrawler Apr 8, 2024
8210443
- don't rely on the terraform module file
MatrixCrawler Apr 8, 2024
0f20b3b
- exit on version or usage print
MatrixCrawler Apr 8, 2024
9fd3ecb
Apply suggestions from code review
MatrixCrawler Apr 8, 2024
ef6418e
- fix imports and fix cancellation of prompt
MatrixCrawler Apr 8, 2024
05bd380
- fix race condition with waiting for deferred file closes and renami…
MatrixCrawler Apr 9, 2024
cf1e230
- update to hcl/v2 package
MatrixCrawler Apr 9, 2024
09fed37
Apply suggestions from code review
MatrixCrawler Apr 11, 2024
778ffcc
Apply suggestions from code review
MatrixCrawler Apr 11, 2024
753cb53
- added log-level parameter
MatrixCrawler Apr 11, 2024
ef175f6
- moved all utility functions out of main.
MatrixCrawler Apr 11, 2024
dee1bd6
- added log-level to toml file
MatrixCrawler Apr 11, 2024
3c75651
- sort if block alphabetically
MatrixCrawler Apr 11, 2024
8286b20
- added test for defect terragrunt decalaration
MatrixCrawler Apr 16, 2024
cb39011
- added test for non existing file for .tfswitchrc file
MatrixCrawler Apr 16, 2024
bc11354
- added test for non existing and erroneous file for tfswitch.toml file
MatrixCrawler Apr 16, 2024
5f7b627
- added test for non existing, erroneous terraform module file
MatrixCrawler Apr 16, 2024
7dfa3c9
- fixed comment counter
MatrixCrawler Apr 16, 2024
f3ba257
- added an exception for integration tests as an empty or an erroneou…
MatrixCrawler Apr 16, 2024
d039a67
- added integration tests for windows
MatrixCrawler Apr 16, 2024
30710fc
Revert "- added integration tests for windows"
MatrixCrawler Apr 16, 2024
12ef46d
- use filepath.Join instead of concatenating strings
MatrixCrawler Apr 19, 2024
34e13d8
- use filepath.Join instead of concatenating strings
MatrixCrawler Apr 19, 2024
48b744b
- use filepath.Join instead of concatenating strings
MatrixCrawler Apr 19, 2024
7d4d411
- replaced if else with switch statement
MatrixCrawler Apr 19, 2024
a08c5ee
- remove commented lines
MatrixCrawler Apr 21, 2024
a316885
- show caller only if not info logging level
MatrixCrawler Apr 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
- fix logging
MatrixCrawler committed Apr 21, 2024
commit 06e781751f6ec40f4ead82420dd7286c733142b3
3 changes: 1 addition & 2 deletions lib/param_parsing/terraform_version.go
Original file line number Diff line number Diff line change
@@ -14,8 +14,7 @@ func GetParamsFromTerraformVersion(params Params) Params {
logger.Infof("Reading configuration from %q", filePath)
content, err := os.ReadFile(filePath)
if err != nil {
logger.Errorf("Could not read file content at %q: %v", filePath, err)
os.Exit(1)
logger.Fatalf("Could not read file content at %q: %v", filePath, err)
}
params.Version = strings.TrimSpace(string(content))
}
4 changes: 0 additions & 4 deletions lib/param_parsing/terragrunt.go
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ import (
"github.com/hashicorp/hcl2/gohcl"
"github.com/hashicorp/hcl2/hclparse"
"github.com/warrensbox/terraform-switcher/lib"
"os"
)

const terraGruntFileName = "terragrunt.hcl"
@@ -21,18 +20,15 @@ func GetVersionFromTerragrunt(params Params) Params {
hclFile, diagnostics := parser.ParseHCLFile(filePath)
if diagnostics.HasErrors() {
logger.Fatalf("Unable to parse HCL file %q", filePath)
os.Exit(1)
}
var versionFromTerragrunt terragruntVersionConstraints
diagnostics = gohcl.DecodeBody(hclFile.Body, nil, &versionFromTerragrunt)
if diagnostics.HasErrors() {
logger.Fatalf("Could not decode body of HCL file %q", filePath)
os.Exit(1)
}
version, err := lib.GetSemver(versionFromTerragrunt.TerraformVersionConstraint, params.MirrorURL)
if err != nil {
logger.Fatalf("No version found matching %q", versionFromTerragrunt.TerraformVersionConstraint)
os.Exit(1)
}
params.Version = version
}