Skip to content

Commit 8d37274

Browse files
committed
Allow init args to be accessed before calling separate init run logic
1 parent bf35c9f commit 8d37274

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

internal/command/init.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,18 @@ type InitCommand struct {
3939
}
4040

4141
func (c *InitCommand) Run(args []string) int {
42-
return c.run(args)
42+
var diags tfdiags.Diagnostics
43+
args = c.Meta.process(args)
44+
initArgs, initDiags := arguments.ParseInit(args)
45+
46+
view := views.NewInit(initArgs.ViewType, c.View)
47+
48+
if initDiags.HasErrors() {
49+
diags = diags.Append(initDiags)
50+
view.Diagnostics(diags)
51+
return 1
52+
}
53+
return c.run(initArgs, view)
4354
}
4455

4556
func (c *InitCommand) getModules(ctx context.Context, path, testsDir string, earlyRoot *configs.Module, upgrade bool, view views.Init) (output bool, abort bool, diags tfdiags.Diagnostics) {

internal/command/init_run.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,8 @@ import (
2121
"go.opentelemetry.io/otel/trace"
2222
)
2323

24-
func (c *InitCommand) run(args []string) int {
24+
func (c *InitCommand) run(initArgs *arguments.Init, view views.Init) int {
2525
var diags tfdiags.Diagnostics
26-
args = c.Meta.process(args)
27-
initArgs, initDiags := arguments.ParseInit(args)
28-
29-
view := views.NewInit(initArgs.ViewType, c.View)
30-
31-
if initDiags.HasErrors() {
32-
diags = diags.Append(initDiags)
33-
view.Diagnostics(diags)
34-
return 1
35-
}
3626

3727
c.forceInitCopy = initArgs.ForceInitCopy
3828
c.Meta.stateLock = initArgs.StateLock

0 commit comments

Comments
 (0)