-
Notifications
You must be signed in to change notification settings - Fork 33
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 go modules and refactor packages #8
Merged
alexandrst88
merged 2 commits into
alexandrst88:master
from
dreamteam-gg:modules-refector
Apr 3, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
terraform-variables-generator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
language: go | ||
go: | ||
- 1.9 | ||
- 1.12 | ||
env: | ||
- GO111MODULE=on | ||
# Don't email me the results of the test runs. | ||
notifications: | ||
email: false | ||
before_script: | ||
- go get github.com/golang/lint/golint # Linter | ||
- go get -u golang.org/x/lint/golint # Linter | ||
- go get -u github.com/golangci/golangci-lint/cmd/golangci-lint | ||
|
||
script: | ||
- go test -v -race ./... # Run all the tests with the race detector enabled | ||
- go vet ./... # go vet is the official Go static analyzer | ||
- golint -set_exit_status $(go list ./...) # one last linter | ||
- golint -set_exit_status $(go list ./...) # one last linter | ||
- golangci-lint run # some more linters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
## (Unreleased) | ||
|
||
ENHANCEMENTS: | ||
* Optimize project structure, split to separate packages and add cobra for cli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
log "github.com/sirupsen/logrus" | ||
|
||
"github.com/alexandrst88/terraform-variables-generator/pkg/generator" | ||
"github.com/alexandrst88/terraform-variables-generator/pkg/utils" | ||
) | ||
|
||
const ( | ||
tfFileExt = "*.tf" | ||
) | ||
|
||
var ( | ||
generatorVersion string | ||
|
||
vars bool | ||
varsFile string | ||
) | ||
|
||
// Execute will run main logic | ||
func Execute(version string) { | ||
generatorVersion = version | ||
|
||
cmd := &cobra.Command{ | ||
Use: "generator", | ||
Short: "CLI for generating terraform variables", | ||
Example: " terraform-variable-generator", | ||
Version: generatorVersion, | ||
Run: runGenerator, | ||
} | ||
|
||
cmd.PersistentFlags().BoolVar(&vars, "vars", true, "generate variables") | ||
cmd.PersistentFlags().StringVar(&varsFile, "vars-file", "./variables.tf", "path to generated variables file") | ||
|
||
if err := cmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
os.Exit(0) | ||
} | ||
|
||
func runGenerator(cmd *cobra.Command, args []string) { | ||
if vars { | ||
if utils.FileExists(varsFile) { | ||
utils.UserPromt(varsFile) | ||
} | ||
|
||
tfFiles, err := utils.GetAllFiles(tfFileExt) | ||
utils.CheckError(err) | ||
if len(tfFiles) == 0 { | ||
log.Warn("No terraform files to proceed, exiting") | ||
return | ||
} | ||
|
||
generator.GenerateVars(tfFiles, varsFile) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module github.com/alexandrst88/terraform-variables-generator | ||
|
||
go 1.12 | ||
|
||
require ( | ||
github.com/sirupsen/logrus v1.4.1 | ||
github.com/spf13/cobra v0.0.3 | ||
github.com/spf13/pflag v1.0.3 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k= | ||
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= | ||
github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8= | ||
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= | ||
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= | ||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= | ||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= | ||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8= | ||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package main | ||
|
||
import "github.com/alexandrst88/terraform-variables-generator/cmd" | ||
|
||
// Version is updated by linker flags during build time | ||
var Version = "dev" | ||
|
||
func main() { | ||
cmd.Execute(Version) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// CheckError is a convenient wrapper for error check | ||
func CheckError(e error) { | ||
if e != nil { | ||
log.Fatal(e) | ||
} | ||
} | ||
|
||
// ContainsElement check if slice of strings contains provided string | ||
func ContainsElement(slice []string, value string) bool { | ||
if len(slice) == 0 { | ||
return false | ||
} | ||
for _, s := range slice { | ||
if value == s { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
// UserPromt will ask user if file needs to be overridden | ||
func UserPromt(dstFile string) { | ||
var response string | ||
log.Warnf("File %q already exists, type 'yes' if you want replace it", dstFile) | ||
fmt.Print("-> ") | ||
_, err := fmt.Scanln(&response) | ||
CheckError(err) | ||
if response != "yes" { | ||
os.Exit(0) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are your thoughts about cobra vs kingpin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/alecthomas/kingpin last commit 9 month ago, either it's perfect or dead. I'll check if we can use it.