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

feat: exec command implementation #3696

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
73bec7a
fix: exec command implementation
levkohimins Dec 14, 2024
e5414c0
fix: flags duplication
levkohimins Dec 15, 2024
58a1e68
chore: update golangci-lint
levkohimins Dec 15, 2024
e4fb601
fix: log level
levkohimins Dec 15, 2024
6252aae
fix: revert pointer
levkohimins Dec 15, 2024
4b1b428
fix: no-color flag duplication
levkohimins Dec 15, 2024
07da3b2
fix: golint
levkohimins Dec 15, 2024
00e47f3
fix: strict mode test
levkohimins Dec 16, 2024
3c5c517
chore: deprecated name funcs improvement
levkohimins Dec 17, 2024
06950e7
fix: deprecated names prefix
levkohimins Dec 17, 2024
38e95b4
chore: handle formatter error
levkohimins Dec 18, 2024
2e56b81
chore: debugging provider cache
levkohimins Dec 18, 2024
aa9afe4
chore: remove debug code
levkohimins Dec 18, 2024
d17e292
chore: debug code
levkohimins Dec 18, 2024
e07d93e
fix: update test envs
levkohimins Dec 19, 2024
bd710c4
chore: exec-cmd integration test
levkohimins Dec 19, 2024
2919cbb
chore: docs update
levkohimins Dec 20, 2024
a05afe3
fix: app_test
levkohimins Dec 20, 2024
b9b82fc
fix: markdown
levkohimins Dec 20, 2024
7281497
fix: markdown
levkohimins Dec 20, 2024
4f04342
fix: tests
levkohimins Dec 20, 2024
6635e0c
fix: render-json flag names
levkohimins Dec 20, 2024
a064757
chore: get rid of unnecessary flags for some commands
levkohimins Dec 20, 2024
1248c4c
chore: docs update
levkohimins Dec 20, 2024
49d0be4
chore: make `-non-interactive` flag global.
levkohimins Dec 20, 2024
c3e8b99
fix: test
levkohimins Dec 20, 2024
472e7fe
chore: docs update
levkohimins Dec 20, 2024
1a21c47
Merge branch 'main' into feat/exec-cmd
levkohimins Dec 20, 2024
5706817
chore: docs update
levkohimins Dec 20, 2024
45d22e6
Merge branch 'main' into feat/exec-cmd
levkohimins Dec 27, 2024
d2d1676
fix: test
levkohimins Dec 27, 2024
959c17a
fix: strict go lint
levkohimins Dec 27, 2024
35e6545
Merge branch 'main' into feat/exec-cmd
levkohimins Dec 30, 2024
58011f1
chore: resolve conflict
levkohimins Dec 30, 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
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ linters:
- nolintlint
- wrapcheck
- varnamelen
- recvcheck

fast: false
mnd:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ clean:
rm -f terragrunt

install-lint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2

run-lint:
golangci-lint run -v --timeout=10m ./...
Expand Down
41 changes: 37 additions & 4 deletions cli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"sort"
"strings"

"github.com/gruntwork-io/terragrunt/engine"
"github.com/gruntwork-io/terragrunt/internal/os/exec"
Expand All @@ -19,6 +20,7 @@ import (

"github.com/gruntwork-io/terragrunt/cli/commands/graph"
"github.com/gruntwork-io/terragrunt/cli/commands/hclvalidate"
"github.com/gruntwork-io/terragrunt/cli/flags"

"github.com/gruntwork-io/terragrunt/cli/commands/scaffold"

Expand All @@ -31,9 +33,9 @@ import (
hashicorpversion "github.com/hashicorp/go-version"

"github.com/gruntwork-io/go-commons/env"
"github.com/gruntwork-io/terragrunt/cli/commands"
awsproviderpatch "github.com/gruntwork-io/terragrunt/cli/commands/aws-provider-patch"
"github.com/gruntwork-io/terragrunt/cli/commands/catalog"
execCmd "github.com/gruntwork-io/terragrunt/cli/commands/exec"
graphdependencies "github.com/gruntwork-io/terragrunt/cli/commands/graph-dependencies"
"github.com/gruntwork-io/terragrunt/cli/commands/hclfmt"
outputmodulegroups "github.com/gruntwork-io/terragrunt/cli/commands/output-module-groups"
Expand Down Expand Up @@ -68,9 +70,7 @@ func NewApp(opts *options.TerragruntOptions) *App {
app.Writer = opts.Writer
app.ErrWriter = opts.ErrWriter

app.Flags = append(
commands.NewGlobalFlags(opts),
NewDeprecatedFlags(opts)...)
app.Flags = flags.NewGlobalFlags(opts)

app.Commands = append(
DeprecatedCommands(opts),
Expand Down Expand Up @@ -134,13 +134,39 @@ func (app *App) RunContext(ctx context.Context, args []string) error {
}
}(ctx)

args = removeNoColorFlagDuplicates(args)

if err := app.App.RunContext(ctx, args); err != nil && !errors.IsContextCanceled(err) {
return err
}

return nil
}

// removeNoColorFlagDuplicates removes one of the `--no-color` or `--terragrunt-no-color` arguments if both are present.
// We have to do this because `--terragrunt-no-color` is a deprecated alias for `--no-color`,
// therefore we end up specifying the same flag twice, which causes the `setting the flag multiple times` error.
func removeNoColorFlagDuplicates(args []string) []string {
var ( //nolint:prealloc
foundNoColor bool
filteredArgs []string
)

for _, arg := range args {
if strings.HasSuffix(arg, "-"+flags.NoColorFlagName) {
if foundNoColor {
continue
}

foundNoColor = true
}

filteredArgs = append(filteredArgs, arg)
}

return filteredArgs
}

// TerragruntCommands returns the set of Terragrunt commands.
func TerragruntCommands(opts *options.TerragruntOptions) cli.Commands {
cmds := cli.Commands{
Expand All @@ -156,6 +182,7 @@ func TerragruntCommands(opts *options.TerragruntOptions) cli.Commands {
scaffold.NewCommand(opts), // scaffold
graph.NewCommand(opts), // graph
hclvalidate.NewCommand(opts), // hclvalidate
execCmd.NewCommand(opts), // exec
}

sort.Sort(cmds)
Expand Down Expand Up @@ -270,6 +297,12 @@ func initialSetup(cliCtx *cli.Context, opts *options.TerragruntOptions) error {
args = append([]string{cmdName}, args...)
}

// Since Terragrunt and Terraform have the same `-no-color` flag,
// if a user specifies `-no-color` for Terragrunt, we should propagate it to Terraform as well.
if opts.DisableLogColors {
args = append(args, terraform.FlagNameNoColor)
}

opts.TerraformCommand = cmdName
opts.TerraformCliArgs = args

Expand Down
Loading