format

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2025 License: MIT Imports: 19 Imported by: 1

Documentation

Overview

Package format provides different, out of the box supported, output format types.

Usage

A specific format can be instantiated either with `format.New()` function or directly calling its function (e.g. `NewMarkdownTable`, etc)

config := print.DefaultConfig()
config.Formatter = "markdown table"

formatter, err := format.New(config)
if err != nil {
    return err
}

err := formatter.Generate(tfmodule)
if err != nil {
    return err
}

output, err := formatter.Render"")
if err != nil {
    return err
}

Note: if you don't intend to provide additional template for the generated content, or the target format doesn't provide templating (e.g. json, yaml, xml, or toml) you can use `Content()` function instead of `Render)`. Note that `Content()` returns all the sections combined with predefined order.

output := formatter.Content()

Supported formats are:

• `NewAsciidocDocument` • `NewAsciidocTable` • `NewJSON` • `NewMarkdownDocument` • `NewMarkdownTable` • `NewPretty` • `NewTfvarsHCL` • `NewTfvarsJSON` • `NewTOML` • `NewXML` • `NewYAML`

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrintFencedAsciidocCodeBlock

func PrintFencedAsciidocCodeBlock(code string, language string) (string, bool)

PrintFencedAsciidocCodeBlock prints codes in fences, it automatically detects if the input 'code' contains '\n' it will use multi line fence, otherwise it wraps the 'code' inside single-tick block. If the fenced is multi-line it also appens an extra '\n` at the end and returns true accordingly, otherwise returns false for non-carriage return.

func PrintFencedCodeBlock

func PrintFencedCodeBlock(code string, language string) (string, bool)

PrintFencedCodeBlock prints codes in fences, it automatically detects if the input 'code' contains '\n' it will use multi line fence, otherwise it wraps the 'code' inside single-tick block. If the fenced is multi-line it also appens an extra '\n` at the end and returns true accordingly, otherwise returns false for non-carriage return.

Types

type Type

type Type interface {
	Generate(*terraform.Module) error // generate the Terraform module

	Content() string // all the sections combined based on the underlying format

	Header() string       // header section based on the underlying format
	Footer() string       // footer section based on the underlying format
	Inputs() string       // inputs section based on the underlying format
	Modules() string      // modules section based on the underlying format
	Outputs() string      // outputs section based on the underlying format
	Providers() string    // providers section based on the underlying format
	Requirements() string // requirements section based on the underlying format
	Resources() string    // resources section based on the underlying format

	Render(tmpl string) (string, error)
}

Type represents an output format type (e.g. json, markdown table, yaml, etc).

func New

func New(config *print.Config) (Type, error)

New initializes and returns the concrete implementation of format.Engine based on the provided 'name', for example for name of 'json' it will return '*format.JSON' through 'format.NewJSON' function.

func NewAsciidocDocument

func NewAsciidocDocument(config *print.Config) Type

NewAsciidocDocument returns new instance of Asciidoc Document.

func NewAsciidocTable

func NewAsciidocTable(config *print.Config) Type

NewAsciidocTable returns new instance of Asciidoc Table.

func NewJSON

func NewJSON(config *print.Config) Type

NewJSON returns new instance of JSON.

func NewMarkdownDocument

func NewMarkdownDocument(config *print.Config) Type

NewMarkdownDocument returns new instance of Markdown Document.

func NewMarkdownTable

func NewMarkdownTable(config *print.Config) Type

NewMarkdownTable returns new instance of Markdown Table.

func NewPretty

func NewPretty(config *print.Config) Type

NewPretty returns new instance of Pretty.

func NewTOML

func NewTOML(config *print.Config) Type

NewTOML returns new instance of TOML.

func NewTfvarsHCL

func NewTfvarsHCL(config *print.Config) Type

NewTfvarsHCL returns new instance of TfvarsHCL.

func NewTfvarsJSON

func NewTfvarsJSON(config *print.Config) Type

NewTfvarsJSON returns new instance of TfvarsJSON.

func NewXML

func NewXML(config *print.Config) Type

NewXML returns new instance of XML.

func NewYAML

func NewYAML(config *print.Config) Type

NewYAML returns new instance of YAML.

Jump to

Keyboard shortcuts

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