2017-02-28 19:58:29 +01:00
|
|
|
package local
|
|
|
|
|
|
|
|
import (
|
2018-11-15 01:03:14 +01:00
|
|
|
"log"
|
|
|
|
|
2017-02-28 19:58:29 +01:00
|
|
|
"github.com/hashicorp/terraform/backend"
|
2021-01-12 03:29:39 +01:00
|
|
|
"github.com/hashicorp/terraform/command/format"
|
2017-02-28 19:58:29 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// backend.CLI impl.
|
|
|
|
func (b *Local) CLIInit(opts *backend.CLIOpts) error {
|
|
|
|
b.CLI = opts.CLI
|
|
|
|
b.CLIColor = opts.CLIColor
|
2021-01-12 03:20:58 +01:00
|
|
|
b.Streams = opts.Streams
|
2018-03-21 02:43:02 +01:00
|
|
|
b.ShowDiagnostics = opts.ShowDiagnostics
|
2017-02-28 19:58:29 +01:00
|
|
|
b.ContextOpts = opts.ContextOpts
|
|
|
|
b.OpInput = opts.Input
|
|
|
|
b.OpValidation = opts.Validation
|
2017-09-09 02:14:37 +02:00
|
|
|
b.RunningInAutomation = opts.RunningInAutomation
|
2017-02-28 19:58:29 +01:00
|
|
|
|
2018-10-17 02:47:23 +02:00
|
|
|
// configure any new cli options
|
|
|
|
if opts.StatePath != "" {
|
2018-11-15 01:03:14 +01:00
|
|
|
log.Printf("[TRACE] backend/local: CLI option -state is overriding state path to %s", opts.StatePath)
|
|
|
|
b.OverrideStatePath = opts.StatePath
|
2018-10-17 02:47:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if opts.StateOutPath != "" {
|
2018-11-15 01:03:14 +01:00
|
|
|
log.Printf("[TRACE] backend/local: CLI option -state-out is overriding state output path to %s", opts.StateOutPath)
|
|
|
|
b.OverrideStateOutPath = opts.StateOutPath
|
2018-10-17 02:47:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if opts.StateBackupPath != "" {
|
2018-11-15 01:03:14 +01:00
|
|
|
log.Printf("[TRACE] backend/local: CLI option -backup is overriding state backup path to %s", opts.StateBackupPath)
|
|
|
|
b.OverrideStateBackupPath = opts.StateBackupPath
|
2017-02-28 19:58:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2021-01-12 03:20:58 +01:00
|
|
|
|
|
|
|
// outputColumns returns the number of text character cells any non-error
|
|
|
|
// output should be wrapped to.
|
|
|
|
//
|
|
|
|
// This is the number of columns to use if you are calling b.CLI.Output or
|
|
|
|
// b.CLI.Info.
|
|
|
|
func (b *Local) outputColumns() int {
|
|
|
|
if b.Streams == nil {
|
|
|
|
// We can potentially get here in tests, if they don't populate the
|
|
|
|
// CLIOpts fully.
|
|
|
|
return 78 // placeholder just so we don't panic
|
|
|
|
}
|
|
|
|
return b.Streams.Stdout.Columns()
|
|
|
|
}
|
|
|
|
|
|
|
|
// errorColumns returns the number of text character cells any error
|
|
|
|
// output should be wrapped to.
|
|
|
|
//
|
|
|
|
// This is the number of columns to use if you are calling b.CLI.Error or
|
|
|
|
// b.CLI.Warn.
|
|
|
|
func (b *Local) errorColumns() int {
|
|
|
|
if b.Streams == nil {
|
|
|
|
// We can potentially get here in tests, if they don't populate the
|
|
|
|
// CLIOpts fully.
|
|
|
|
return 78 // placeholder just so we don't panic
|
|
|
|
}
|
|
|
|
return b.Streams.Stderr.Columns()
|
|
|
|
}
|
2021-01-12 03:29:39 +01:00
|
|
|
|
|
|
|
// outputHorizRule will call b.CLI.Output with enough horizontal line
|
|
|
|
// characters to fill an entire row of output.
|
|
|
|
//
|
|
|
|
// This function does nothing if the backend doesn't have a CLI attached.
|
|
|
|
//
|
|
|
|
// If UI color is enabled, the rule will get a dark grey coloring to try to
|
|
|
|
// visually de-emphasize it.
|
|
|
|
func (b *Local) outputHorizRule() {
|
|
|
|
if b.CLI == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
b.CLI.Output(format.HorizontalRule(b.CLIColor, b.outputColumns()))
|
|
|
|
}
|