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

Added -verbose=true cli flag #61

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 23 additions & 12 deletions cli/cli.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,46 @@
package cli

import (
"github.com/env0/terratag/errors"
"log"
"os"
"strconv"
"strings"

"github.com/env0/terratag/errors"
)

func InitArgs() (string, string, bool, bool) {
var tags string
var dir string
var skipTerratagFiles string
var isSkipTerratagFiles bool
type Args struct {
Tags string
Dir string
SkipTerratagFiles string
IsSkipTerratagFiles bool
Verbose bool
}

func InitArgs() (Args, bool) {
args := Args{}
isMissingArg := false

tags = setFlag("tags", "")
dir = setFlag("dir", ".")
skipTerratagFiles = setFlag("skipTerratagFiles", "true")
args.Tags = setFlag("tags", "")
args.Dir = setFlag("dir", ".")
skipTerratagFiles := setFlag("skipTerratagFiles", "true")
verbose := setFlag("verbose", "false")

if tags == "" {
if args.Tags == "" {
log.Println("Usage: terratag -tags='{ \"some_tag\": \"value\" }' [-dir=\".\"]")
isMissingArg = true
}

isSkipTerratagFiles, err := strconv.ParseBool(skipTerratagFiles)
var err error
args.IsSkipTerratagFiles, err = strconv.ParseBool(skipTerratagFiles)
errorMessage := "-skipTerratagFiles may only be set to true or false"
errors.PanicOnError(err, &errorMessage)

return tags, dir, isSkipTerratagFiles, isMissingArg
args.Verbose, err = strconv.ParseBool(verbose)
errorMessage2 := "-verbose may only be set to true or false"
errors.PanicOnError(err, &errorMessage2)

return args, isMissingArg
}

func setFlag(flag string, defaultValue string) string {
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ go 1.13

require (
github.com/bmatcuk/doublestar v1.2.2
github.com/hashicorp/go-hclog v0.9.2
github.com/hashicorp/hcl/v2 v2.6.0
github.com/hashicorp/logutils v1.0.0
github.com/minamijoyo/tfschema v0.5.0
github.com/mitchellh/mapstructure v1.1.2
github.com/onsi/gomega v1.10.1
github.com/otiai10/copy v1.2.0
github.com/thoas/go-funk v0.5.0
Expand Down
Loading