Skip to content

Commit

Permalink
tf show command without arguments or with plan works as original
Browse files Browse the repository at this point in the history
  • Loading branch information
dex4er committed Sep 14, 2023
1 parent 4aca9a2 commit ebac793
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 27 deletions.
3 changes: 1 addition & 2 deletions run/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ func List(args []string) error {
}
}

patternIgnoreFooter := ""
return terraformWithoutColors("state", newArgs, patternIgnoreFooter)
return terraformWithoutColors("state", newArgs)
}
18 changes: 3 additions & 15 deletions run/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,28 @@ func Show(args []string) error {
resources := []string{}
newArgs := []string{}

noOutputs := true

for _, arg := range args {
if arg == "-no-output" || arg == "-no-outputs" {
noOutputs = true
} else if arg == "-no-output=false" || arg == "-no-outputs=false" {
noOutputs = false
} else if strings.HasPrefix(arg, "-") {
if strings.HasPrefix(arg, "-") {
newArgs = append(newArgs, arg)
} else if _, err := os.Stat(arg); err == nil {
newArgs = append(newArgs, arg)
} else {
resources = append(resources, util.AddQuotes(arg))
}

}

patternIgnoreFooter := ""

if len(resources) > 0 {
newArgs = append([]string{"show"}, newArgs...)
for i, r := range resources {
if i > 0 {
fmt.Println()
}
if err := terraformWithoutColors("state", append(newArgs, r), patternIgnoreFooter); err != nil {
if err := terraformWithoutColors("state", append(newArgs, r)); err != nil {
return err
}
}
return nil
}

if noOutputs {
patternIgnoreFooter = `^Outputs:$`
}
return terraformWithoutColors("show", newArgs, patternIgnoreFooter)
return Terraform("show", newArgs)
}
11 changes: 1 addition & 10 deletions run/terraform_without_colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ import (
"fmt"
"os"
"os/signal"
"regexp"
"syscall"

"github.com/dex4er/tf/util"
)

func terraformWithoutColors(command string, args []string, patternIgnoreFooter string) error {
reIgnoreFooter := regexp.MustCompile(patternIgnoreFooter)

func terraformWithoutColors(command string, args []string) error {
signal.Ignore(syscall.SIGINT)

cmd := execTerraformCommand(append([]string{command}, args...)...)
Expand Down Expand Up @@ -42,12 +39,6 @@ func terraformWithoutColors(command string, args []string, patternIgnoreFooter s
line := scanner.Text()
line = util.RemoveColors(line)

// ignore from this line to the end
if patternIgnoreFooter != "" && reIgnoreFooter.MatchString(line) {
ignoreFooter = true
continue
}

fmt.Println(line)
}

Expand Down

0 comments on commit ebac793

Please sign in to comment.