formatter

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Formatter

type Formatter struct {
	// contains filtered or unexported fields
}

Formatter represents the data structure which controls how output is handled

func New

func New(suffix string, mode Mode) (*Formatter, error)

New provides a formatter with output format determined by the mode.

If the formatter detects that it is within a TTY and in pretty mode, it will switch to plain mode. This avoids any mistaken garbaled output for none terminal destinations.

The suffix parameter is only applicable to pretty mode. Suffix is the string of text printed right after the spinner. (Hence the name, despite there being other text after it.)

func (*Formatter) PrintAllRulesets

func (f *Formatter) PrintAllRulesets(rulesets []models.Ruleset)

PrintAllRulesets formats and outputs all currently installed rulesets

func (*Formatter) PrintError

func (f *Formatter) PrintError(suffix, msg string)

PrintError outputs an error. In pretty mode it will cause it to print the message replacing the current suffix and immediately start a new spinner.

func (*Formatter) PrintFinalError

func (f *Formatter) PrintFinalError(msg string)

PrintFinalError prints an error; usually to end the program on. In pretty mode this will stop the spinner, display a red x and not start a new one. In all other modes this will simply print an error message.

func (*Formatter) PrintFinalSuccess

func (f *Formatter) PrintFinalSuccess(msg string)

PrintFinalSuccess prints a final success message; usually to end the program on. In pretty mode this will stop the spinner, display a green checkmark and not start a new one. In all other modes this will simply print an info message.

func (*Formatter) PrintLintError

func (f *Formatter) PrintLintError(details LintErrorDetails)

PrintLintError formats and prints details from a lint error.

It borrows(blatantly copies) from rust style errors: https://doc.rust-lang.org/edition-guide/rust-2018/the-compiler/improved-error-messages.html

Example format:

x Error: lolwut is inherently unsafe; see link for more details

  --> ./testdata/test1.tf:17:1
    |
 17 | lolwut = "weow"
    |
	|
 = additional information:
  • rule name: resource_should_not_contain_attr_lolwut
  • link: http://lolwut.com/
  • more info: tfvet rule describe example resource_should_not_contain_attr_lolwut
  • remediation: some text here about how to fix the problem.
  • remediation: `some code to fix the issue`

func (*Formatter) PrintMsg

func (f *Formatter) PrintMsg(msg string)

PrintMsg outputs a simple message. In pretty mode it will display it after the suffix text.

func (*Formatter) PrintRuleset

func (f *Formatter) PrintRuleset(ruleset models.Ruleset)

PrintRuleset formats and outputs the information for a single ruleset

func (*Formatter) PrintStandaloneMsg

func (f *Formatter) PrintStandaloneMsg(msg string)

PrintStandaloneMsg outputs a message unattached to the spinner or suffix text. In pretty mode this causes the spinner to first stop, print the message, and then immediately start a new spinner as to not cause the spinner suffix text to be printed.

func (*Formatter) PrintSuccess

func (f *Formatter) PrintSuccess(msg string)

PrintSuccess outputs a success message. Pretty mode will cause it to print the message with a checkmark, replacing the current suffix, and immediately start a new spinner.

func (*Formatter) UpdateSuffix

func (f *Formatter) UpdateSuffix(text string)

UpdateSuffix updates the text that comes right after the spinner.

type LintErrorDetails

type LintErrorDetails struct {
	Filepath string
	Line     string
	Ruleset  string
	Rule     models.Rule
	LintErr  *proto.RuleError
}

LintErrorDetails is a harness for all the details that go into a lint error

type Mode

type Mode string

Mode is the type of formatting to output. Plain logging, pretty print, or json provided.

const (
	// Plain pretty prints json but indented and colorized.
	Plain Mode = "plain"
	// Pretty outputs text in a more humanized fashion and provides spinners for longer actions.
	Pretty Mode = "pretty"
	// JSON outputs json formatted text, mainly suitable to be read by computers.
	JSON Mode = "json"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL