Skip to content

Commit

Permalink
Merge branch 'main' of ssh://github.com/speier/atmos
Browse files Browse the repository at this point in the history
  • Loading branch information
speier committed Nov 4, 2024
2 parents 6df88bf + 753f213 commit e40166f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ require (
github.com/jwalton/go-supportscolor v1.2.0
github.com/kubescape/go-git-url v0.0.30
github.com/lrstanley/bubblezone v0.0.0-20240914071701-b48c55a5e78e
github.com/mattn/go-shellwords v1.0.12
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.5.0
github.com/open-policy-agent/opa v0.70.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,8 @@ github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzp
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=
github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
Expand Down
11 changes: 10 additions & 1 deletion internal/exec/shell_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"os"
"os/exec"
"runtime"
"slices"
"strings"

"github.com/mattn/go-shellwords"
"mvdan.cc/sh/v3/expand"
"mvdan.cc/sh/v3/interp"
"mvdan.cc/sh/v3/syntax"
Expand All @@ -28,7 +30,14 @@ func ExecuteShellCommand(
dryRun bool,
redirectStdError string,
) error {
cmd := exec.Command(command, args...)
parsedArgs, err := shellwords.Parse(command)
if err != nil {
return err
}

cmdName := parsedArgs[0]
cmdArgs := slices.Concat(parsedArgs[1:], args)
cmd := exec.Command(cmdName, cmdArgs...)
cmd.Env = append(os.Environ(), env...)
cmd.Dir = dir
cmd.Stdin = os.Stdin
Expand Down
11 changes: 10 additions & 1 deletion internal/exec/template_funcs_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sync"

"github.com/hashicorp/terraform-exec/tfexec"
"github.com/mattn/go-shellwords"
"github.com/samber/lo"

cfg "github.com/cloudposse/atmos/pkg/config"
Expand Down Expand Up @@ -145,8 +146,16 @@ func componentFunc(cliConfig schema.CliConfiguration, component string, stack st
u.LogTrace(cliConfig, providerOverrideFileName)
}

parsedArgs, err := shellwords.Parse(executable)
if err != nil {
return nil, err
}

// last element should be the command name, terraform, tofu, etc.
cmdName := parsedArgs[len(parsedArgs)-1]

// Initialize Terraform/OpenTofu
tf, err := tfexec.NewTerraform(componentPath, executable)
tf, err := tfexec.NewTerraform(componentPath, cmdName)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit e40166f

Please sign in to comment.