github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/command/views/plan.go (about)

     1  package views
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/hashicorp/terraform/internal/command/arguments"
     7  	"github.com/hashicorp/terraform/internal/terraform"
     8  	"github.com/hashicorp/terraform/internal/tfdiags"
     9  )
    10  
    11  // The Plan view is used for the plan command.
    12  type Plan interface {
    13  	Operation() Operation
    14  	Hooks() []terraform.Hook
    15  
    16  	Diagnostics(diags tfdiags.Diagnostics)
    17  	HelpPrompt()
    18  }
    19  
    20  // NewPlan returns an initialized Plan implementation for the given ViewType.
    21  func NewPlan(vt arguments.ViewType, view *View) Plan {
    22  	switch vt {
    23  	case arguments.ViewJSON:
    24  		return &PlanJSON{
    25  			view: NewJSONView(view),
    26  		}
    27  	case arguments.ViewHuman:
    28  		return &PlanHuman{
    29  			view:         view,
    30  			inAutomation: view.RunningInAutomation(),
    31  		}
    32  	default:
    33  		panic(fmt.Sprintf("unknown view type %v", vt))
    34  	}
    35  }
    36  
    37  // The PlanHuman implementation renders human-readable text logs, suitable for
    38  // a scrolling terminal.
    39  type PlanHuman struct {
    40  	view *View
    41  
    42  	inAutomation bool
    43  }
    44  
    45  var _ Plan = (*PlanHuman)(nil)
    46  
    47  func (v *PlanHuman) Operation() Operation {
    48  	return NewOperation(arguments.ViewHuman, v.inAutomation, v.view)
    49  }
    50  
    51  func (v *PlanHuman) Hooks() []terraform.Hook {
    52  	return []terraform.Hook{
    53  		NewUiHook(v.view),
    54  	}
    55  }
    56  
    57  func (v *PlanHuman) Diagnostics(diags tfdiags.Diagnostics) {
    58  	v.view.Diagnostics(diags)
    59  }
    60  
    61  func (v *PlanHuman) HelpPrompt() {
    62  	v.view.HelpPrompt("plan")
    63  }
    64  
    65  // The PlanJSON implementation renders streaming JSON logs, suitable for
    66  // integrating with other software.
    67  type PlanJSON struct {
    68  	view *JSONView
    69  }
    70  
    71  var _ Plan = (*PlanJSON)(nil)
    72  
    73  func (v *PlanJSON) Operation() Operation {
    74  	return &OperationJSON{view: v.view}
    75  }
    76  
    77  func (v *PlanJSON) Hooks() []terraform.Hook {
    78  	return []terraform.Hook{
    79  		newJSONHook(v.view),
    80  	}
    81  }
    82  
    83  func (v *PlanJSON) Diagnostics(diags tfdiags.Diagnostics) {
    84  	v.view.Diagnostics(diags)
    85  }
    86  
    87  func (v *PlanJSON) HelpPrompt() {
    88  }