Skip to content

Commit 6331977

Browse files
authored
chore: Move log flags off writers (#6403)
1 parent 35a9b85 commit 6331977

20 files changed

Lines changed: 100 additions & 67 deletions

File tree

internal/cli/commands/commands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ func initialSetup(cliCtx *clihelper.Context, l log.Logger, opts *options.Terragr
469469
return err
470470
}
471471

472-
if opts.Writers.LogShowAbsPaths {
472+
if opts.LogShowAbsPaths {
473473
l.Formatter().DisableRelativePaths()
474474
}
475475

internal/cli/flags/global/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func NewFlags(l log.Logger, opts *options.TerragruntOptions, prefix flags.Prefix
116116
flags.NewFlag(&clihelper.BoolFlag{
117117
Name: ShowLogAbsPathsFlagName,
118118
EnvVars: tgPrefix.EnvVars(ShowLogAbsPathsFlagName),
119-
Destination: &opts.Writers.LogShowAbsPaths,
119+
Destination: &opts.LogShowAbsPaths,
120120
Usage: "Show absolute paths in logs.",
121121
},
122122
flags.WithDeprecatedEnvVars(terragruntPrefix.EnvVars(DeprecatedShowLogAbsPathsFlagName), opts.StrictControls)),

internal/configbridge/bridge.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ func populateFromOpts(pctx *config.ParsingContext, opts *options.TerragruntOptio
5757
pctx.StrictControls = opts.StrictControls
5858
pctx.FeatureFlags = opts.FeatureFlags
5959
pctx.Writers = opts.Writers
60+
pctx.LogShowAbsPaths = opts.LogShowAbsPaths
61+
pctx.LogDisableErrorSummary = opts.LogDisableErrorSummary
6062
pctx.Env = opts.Env
6163
pctx.IAMRoleOptions = opts.IAMRoleOptions
6264
pctx.OriginalIAMRoleOptions = opts.OriginalIAMRoleOptions
@@ -88,7 +90,7 @@ func populateFromOpts(pctx *config.ParsingContext, opts *options.TerragruntOptio
8890

8991
// ShellRunOptsFromOpts constructs shell.ShellOptions from TerragruntOptions.
9092
func ShellRunOptsFromOpts(opts *options.TerragruntOptions) *shell.ShellOptions {
91-
return shell.NewShellOptions().
93+
s := shell.NewShellOptions().
9294
WithWorkingDir(opts.WorkingDir).
9395
WithEnv(opts.Env).
9496
WithWriters(opts.Writers).
@@ -99,6 +101,10 @@ func ShellRunOptsFromOpts(opts *options.TerragruntOptions) *shell.ShellOptions {
99101
WithExperiments(opts.Experiments).
100102
WithHeadless(opts.Headless).
101103
WithForwardTFStdout(opts.ForwardTFStdout)
104+
s.LogShowAbsPaths = opts.LogShowAbsPaths
105+
s.LogDisableErrorSummary = opts.LogDisableErrorSummary
106+
107+
return s
102108
}
103109

104110
// BackendOptsFromOpts constructs backend.Options from TerragruntOptions.
@@ -138,6 +144,8 @@ func TFRunOptsFromOpts(opts *options.TerragruntOptions) *tf.TFOptions {
138144
func NewRunOptions(opts *options.TerragruntOptions) *run.Options {
139145
runOpts := run.NewOptions()
140146
runOpts.Writers = opts.Writers
147+
runOpts.LogShowAbsPaths = opts.LogShowAbsPaths
148+
runOpts.LogDisableErrorSummary = opts.LogDisableErrorSummary
141149
runOpts.TerragruntConfigPath = opts.TerragruntConfigPath
142150
runOpts.OriginalTerragruntConfigPath = opts.OriginalTerragruntConfigPath
143151
runOpts.WorkingDir = opts.WorkingDir

internal/engine/engine.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ type ExecutionOptions struct {
8282
ForwardTFStdout bool
8383
SuppressStdout bool
8484
AllocatePseudoTty bool
85+
86+
LogShowAbsPaths bool
87+
LogDisableErrorSummary bool
8588
}
8689

8790
type engineInstance struct {
@@ -832,10 +835,10 @@ func invoke(
832835
Output: output,
833836
WorkingDir: runOptions.WorkingDir,
834837
RootWorkingDir: runOptions.RootWorkingDir,
835-
LogShowAbsPaths: runOptions.Writers.LogShowAbsPaths,
838+
LogShowAbsPaths: runOptions.LogShowAbsPaths,
836839
Command: runOptions.Command,
837840
Args: runOptions.Args,
838-
DisableSummary: runOptions.Writers.LogDisableErrorSummary,
841+
DisableSummary: runOptions.LogDisableErrorSummary,
839842
}
840843

841844
return err

internal/runner/common/unit_runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (runner *UnitRunner) runTerragrunt(
5252
cfg *runcfg.RunConfig,
5353
credsGetter *creds.Getter,
5454
) error {
55-
l.Debugf("Running %s", util.RelPathForLog(opts.RootWorkingDir, runner.Unit.Path(), opts.Writers.LogShowAbsPaths))
55+
l.Debugf("Running %s", util.RelPathForLog(opts.RootWorkingDir, runner.Unit.Path(), opts.LogShowAbsPaths))
5656

5757
defer func() {
5858
// Flush buffered output for this unit, if the writer supports it.

internal/runner/run/download_source.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ func DownloadTerraformSource(
100100
if needsModuleCopy {
101101
l.Debugf(
102102
"Copying files from %s into %s",
103-
util.RelPathForLog(opts.WorkingDir, opts.WorkingDir, opts.Writers.LogShowAbsPaths),
104-
util.RelPathForLog(opts.RootWorkingDir, terraformSource.WorkingDir, opts.Writers.LogShowAbsPaths),
103+
util.RelPathForLog(opts.WorkingDir, opts.WorkingDir, opts.LogShowAbsPaths),
104+
util.RelPathForLog(opts.RootWorkingDir, terraformSource.WorkingDir, opts.LogShowAbsPaths),
105105
)
106106

107107
// Always include the .tflint.hcl file, if it exists
@@ -136,7 +136,7 @@ func DownloadTerraformSource(
136136
util.RelPathForLog(
137137
opts.RootWorkingDir,
138138
terraformSource.WorkingDir,
139-
opts.Writers.LogShowAbsPaths,
139+
opts.LogShowAbsPaths,
140140
),
141141
)
142142
updatedOpts.WorkingDir = terraformSource.WorkingDir
@@ -185,7 +185,7 @@ func DownloadTerraformSourceIfNecessary(
185185
util.RelPathForLog(
186186
opts.RootWorkingDir,
187187
terraformSource.WorkingDir,
188-
opts.Writers.LogShowAbsPaths,
188+
opts.LogShowAbsPaths,
189189
),
190190
)
191191

@@ -348,8 +348,8 @@ func downloadSource(
348348

349349
l.Infof(
350350
"Downloading Terraform configurations from %s into %s",
351-
util.RelPathForLog(opts.RootWorkingDir, canonicalSourceURL, opts.Writers.LogShowAbsPaths),
352-
util.RelPathForLog(opts.RootWorkingDir, src.DownloadDir, opts.Writers.LogShowAbsPaths))
351+
util.RelPathForLog(opts.RootWorkingDir, canonicalSourceURL, opts.LogShowAbsPaths),
352+
util.RelPathForLog(opts.RootWorkingDir, src.DownloadDir, opts.LogShowAbsPaths))
353353

354354
allowCAS := !opts.NoCAS
355355

internal/runner/run/options.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ type Options struct {
8888
DisableBucketUpdate bool
8989
SourceUpdate bool
9090
ForwardTFStdout bool
91+
LogShowAbsPaths bool
92+
LogDisableErrorSummary bool
9193
}
9294

9395
// Clone performs a deep copy of Options.
@@ -192,7 +194,7 @@ func (o *Options) DataDir() string {
192194

193195
// shellRunOptions builds a *shell.ShellOptions from this Options.
194196
func (o *Options) shellRunOptions() *shell.ShellOptions {
195-
return shell.NewShellOptions().
197+
s := shell.NewShellOptions().
196198
WithWorkingDir(o.WorkingDir).
197199
WithEnv(o.Env).
198200
WithWriters(o.Writers).
@@ -203,6 +205,10 @@ func (o *Options) shellRunOptions() *shell.ShellOptions {
203205
WithExperiments(o.Experiments).
204206
WithHeadless(o.Headless).
205207
WithForwardTFStdout(o.ForwardTFStdout)
208+
s.LogShowAbsPaths = o.LogShowAbsPaths
209+
s.LogDisableErrorSummary = o.LogDisableErrorSummary
210+
211+
return s
206212
}
207213

208214
// tfRunOptions builds a *tf.TFOptions from this Options.
@@ -237,6 +243,7 @@ func (o *Options) tflintRunOptions() *tflint.TFLintOptions {
237243
return &tflint.TFLintOptions{
238244
ShellOptions: o.shellRunOptions(),
239245
Writers: o.Writers,
246+
LogShowAbsPaths: o.LogShowAbsPaths,
240247
WorkingDir: o.WorkingDir,
241248
RootWorkingDir: o.RootWorkingDir,
242249
TerragruntConfigPath: o.TerragruntConfigPath,

internal/runner/run/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func runTerragruntWithConfig(
295295
// terragrunt.hcl. However, the default value for the user's working dir, set in options.go, IS just the
296296
// parent dir of terragrunt.hcl, so these will likely always be the same.
297297
// Use directory from OriginalTerragruntConfigPath to copy locks since WorkingDir point to cache directory
298-
lockFileError = runcfg.CopyLockFile(l, opts.RootWorkingDir, opts.Writers.LogShowAbsPaths, opts.WorkingDir, filepath.Dir(opts.OriginalTerragruntConfigPath))
298+
lockFileError = runcfg.CopyLockFile(l, opts.RootWorkingDir, opts.LogShowAbsPaths, opts.WorkingDir, filepath.Dir(opts.OriginalTerragruntConfigPath))
299299
}
300300

301301
// If command failed, log a helpful message

internal/runner/runall/runall.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func RunAllOnStack(
203203
l.Debugf("%s", rnr.GetStack().String())
204204

205205
isDestroy := opts.TerraformCliArgs.IsDestroyCommand(opts.TerraformCommand)
206-
if err := rnr.LogUnitDeployOrder(l, isDestroy, opts.Writers.LogShowAbsPaths, opts.Experiments); err != nil {
206+
if err := rnr.LogUnitDeployOrder(l, isDestroy, opts.LogShowAbsPaths, opts.Experiments); err != nil {
207207
return err
208208
}
209209

internal/runner/runnerpool/runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func CloneUnitOptions(
6060

6161
// Override logger prefix with display path (relative to discovery context) for cleaner logs
6262
// unless --log-show-abs-paths is set
63-
if !stackOpts.Writers.LogShowAbsPaths {
63+
if !stackOpts.LogShowAbsPaths {
6464
clonedLogger = clonedLogger.WithField(placeholders.WorkDirKeyName, unit.DisplayPath())
6565
}
6666

0 commit comments

Comments
 (0)