diff --git a/internal/command/views/init.go b/internal/command/views/init.go new file mode 100644 index 0000000000..80967a2820 --- /dev/null +++ b/internal/command/views/init.go @@ -0,0 +1,56 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + +package views + +import ( + "fmt" + + "github.com/hashicorp/terraform/internal/command/arguments" + "github.com/hashicorp/terraform/internal/tfdiags" +) + +// The Init view is used for the init command. +type Init interface { + Diagnostics(diags tfdiags.Diagnostics) +} + +// NewInit returns Init implementation for the given ViewType. +func NewInit(vt arguments.ViewType, view *View) Init { + switch vt { + case arguments.ViewJSON: + return &InitJSON{ + view: NewJSONView(view), + } + case arguments.ViewHuman: + return &InitHuman{ + view: view, + } + default: + panic(fmt.Sprintf("unknown view type %v", vt)) + } +} + +// The InitHuman implementation renders human-readable text logs, suitable for +// a scrolling terminal. +type InitHuman struct { + view *View +} + +var _ Init = (*InitHuman)(nil) + +func (v *InitHuman) Diagnostics(diags tfdiags.Diagnostics) { + v.view.Diagnostics(diags) +} + +// The InitJSON implementation renders streaming JSON logs, suitable for +// integrating with other software. +type InitJSON struct { + view *JSONView +} + +var _ Init = (*InitJSON)(nil) + +func (v *InitJSON) Diagnostics(diags tfdiags.Diagnostics) { + v.view.Diagnostics(diags) +}