Skip to content

Commit a3f502a

Browse files
feat: Adding list command (#4034)
* feat: Adding `list` as copy of `find` command * fix: Renaming found variables to listed * feat: Format list differently than find * feat: Working tree listing. * feat: Adding tree fixture for list tests * feat: Adding some convenience aliases * fix: Faster tree construction * fix: Minor nits * fix: Working dependency tree graph * feat: Adding `--long` formatting * feat: Standardizing color usage * feat: Updating JSON display for `list` * feat: Better JSON parsing * fix: Adjusting logic for listing * fix: Adjusting JSON logic for listing DAG in JSON * feat: Adding some integration testing * feat: Adding `long` as a standalone format * feat: Hide dependencies in `--long` unless users ask for it * fix: Linting * fix: Use yellow for tree branches * fix: Only show dependencies when asked for * fix: Fixing tests * fix: Cleaning up docs * fix: Refactoring tests * fix: Addressing lint * fix: Improving testing * fix: Improving integration testing * fix: Updating handling of edge-cases * fix: Fixing pathing for JSON entries * feat: Improving fixture for list * fix: Resolving sorting bug * fix: Address type presence in JSON response * fix: Always set the type for the DAG tree * fix: Removing `stage` fixture * feat: Adding docs for `list` command * feat: Adding `docs-starlight` docs * fix: Addressing lints * fix: Fixing tests * feat: More updates to docs * fix: Addressing lints * fix: Checking experiment for `list` * Update cli/commands/find/options.go Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix: Adding more nuance to the status of the `find` and `list` experiments * fix: Addressing markdownlint errors * fix: Dropping `json` from the `list` command (#4043) * feat: Removing sort and group-by for `--dag` mode * fix: Make tree branches less yellow * fix: Updating docs * fix: Fixing tree coloring * fix: Updating assets for docs * fix: Fixing integration tests * fix: Fixing more assets * fix: Removing unused flag names from Starlight docs * fix: Updating `--help` * fix: Updating error handling in `list/action.go` and `find/action.go` * fix: Adding `mode` to find test * fix: Fixing integration tests for find --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 89a9808 commit a3f502a

61 files changed

Lines changed: 2377 additions & 343 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cli/commands/commands.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package commands
44
import (
55
"github.com/gruntwork-io/terragrunt/cli/commands/find"
66
"github.com/gruntwork-io/terragrunt/cli/commands/info"
7+
"github.com/gruntwork-io/terragrunt/cli/commands/list"
78
"github.com/gruntwork-io/terragrunt/cli/commands/stack"
89
"github.com/gruntwork-io/terragrunt/options"
910

@@ -70,6 +71,7 @@ func New(opts *options.TerragruntOptions) cli.Commands {
7071

7172
discoveryCommands := cli.Commands{
7273
find.NewCommand(opts), // find
74+
list.NewCommand(opts), // list
7375
}.SetCategory(
7476
&cli.Category{
7577
Name: DiscoveryCommandsCategoryName,

cli/commands/find/action.go

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func Run(ctx context.Context, opts *Options) error {
2020
d = d.WithHidden()
2121
}
2222

23-
if opts.Dependencies || opts.External || opts.Sort == SortDAG {
23+
if opts.Dependencies || opts.External || opts.Mode == ModeDAG {
2424
d = d.WithDiscoverDependencies()
2525
}
2626

@@ -33,16 +33,20 @@ func Run(ctx context.Context, opts *Options) error {
3333
return errors.New(err)
3434
}
3535

36-
switch opts.Sort {
37-
case SortAlpha:
36+
switch opts.Mode {
37+
case ModeNormal:
3838
cfgs = cfgs.Sort()
39-
case SortDAG:
39+
case ModeDAG:
4040
q, err := queue.NewQueue(cfgs)
4141
if err != nil {
4242
return errors.New(err)
4343
}
4444

4545
cfgs = q.Entries()
46+
default:
47+
// This should never happen, because of validation in the command.
48+
// If it happens, we want to throw so we can fix the validation.
49+
return errors.New("invalid mode: " + opts.Mode)
4650
}
4751

4852
foundCfgs, err := discoveredToFound(cfgs, opts)
@@ -140,7 +144,15 @@ type Colorizer struct {
140144
}
141145

142146
// NewColorizer creates a new Colorizer.
143-
func NewColorizer() *Colorizer {
147+
func NewColorizer(shouldColor bool) *Colorizer {
148+
if !shouldColor {
149+
return &Colorizer{
150+
unitColorizer: func(s string) string { return s },
151+
stackColorizer: func(s string) string { return s },
152+
pathColorizer: func(s string) string { return s },
153+
}
154+
}
155+
144156
return &Colorizer{
145157
unitColorizer: ansi.ColorFunc("blue+bh"),
146158
stackColorizer: ansi.ColorFunc("green+bh"),
@@ -181,18 +193,7 @@ func (c *Colorizer) Colorize(config *FoundConfig) string {
181193

182194
// outputText outputs the discovered configurations in text format.
183195
func outputText(opts *Options, configs FoundConfigs) error {
184-
if opts.TerragruntOptions.Logger.Formatter().DisabledColors() || isStdoutRedirected() {
185-
for _, config := range configs {
186-
_, err := opts.Writer.Write([]byte(config.Path + "\n"))
187-
if err != nil {
188-
return errors.New(err)
189-
}
190-
}
191-
192-
return nil
193-
}
194-
195-
colorizer := NewColorizer()
196+
colorizer := NewColorizer(shouldColor(opts))
196197

197198
for _, config := range configs {
198199
_, err := opts.Writer.Write([]byte(colorizer.Colorize(config) + "\n"))
@@ -204,6 +205,11 @@ func outputText(opts *Options, configs FoundConfigs) error {
204205
return nil
205206
}
206207

208+
// shouldColor returns true if the output should be colored.
209+
func shouldColor(opts *Options) bool {
210+
return !(opts.TerragruntOptions.Logger.Formatter().DisabledColors() || isStdoutRedirected())
211+
}
212+
207213
// isStdoutRedirected returns true if the stdout is redirected.
208214
func isStdoutRedirected() bool {
209215
stat, err := os.Stdout.Stat()

0 commit comments

Comments
 (0)