print

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: MIT Imports: 6 Imported by: 3

Documentation

Overview

Package print provides configuration, and a Generator.

Configuration

`print.Config` is the data structure representation for `.terraform-docs.yml` which will be read and extracted upon execution of terraform-docs cli. On the other hand it can be used directly if you are using terraform-docs as a library.

This will return an instance of `Config` with default values set:

config := print.DefaultConfig()

Alternatively this will return an empty instance of `Config`:

config := print.NewConfig()

Generator

`Generator` is an abstract implementation of `format.Type`. It doesn't implement `Generate(*terraform.Module) error` function. It is used directly by different format types, i.e. each format extends `Generator` and provides its implementation of `Generate` function.

Generator holds a reference to all the sections (e.g. header, footer, inputs, etc) and also it renders all of them, in a predefined order, in `Content()`.

It also provides `Render(string)` function to process and render the template to generate the final output content. Following variables and functions are available:

• `{{ .Header }}` • `{{ .Footer }}` • `{{ .Inputs }}` • `{{ .Modules }}` • `{{ .Outputs }}` • `{{ .Providers }}` • `{{ .Requirements }}` • `{{ .Resources }}` • `{{ include "path/fo/file" }}`

Index

Constants

View Source
const (
	OutputModeInject  = "inject"
	OutputModeReplace = "replace"
)

Output modes.

View Source
const (
	OutputBeginComment = "<!-- BEGIN_TF_DOCS -->"
	OutputContent      = "{{ .Content }}"
	OutputEndComment   = "<!-- END_TF_DOCS -->"
)

Output template.

View Source
const (
	SortName     = "name"
	SortRequired = "required"
	SortType     = "type"
)

Sort types.

Variables

View Source
var (
	OutputTemplate = fmt.Sprintf("%s\n%s\n%s", OutputBeginComment, OutputContent, OutputEndComment)
	OutputModes    = strings.Join([]string{OutputModeInject, OutputModeReplace}, ", ")
)

Output to file template and modes.

View Source
var AllSections = strings.Join(allSections, ", ")

AllSections list.

View Source
var SortTypes = strings.Join(allSorts, ", ")

SortTypes list.

Functions

This section is empty.

Types

type Config added in v0.16.0

type Config struct {
	File         string       `mapstructure:"-"`
	Formatter    string       `mapstructure:"formatter"`
	Version      string       `mapstructure:"version"`
	HeaderFrom   string       `mapstructure:"header-from"`
	FooterFrom   string       `mapstructure:"footer-from"`
	Recursive    recursive    `mapstructure:"recursive"`
	Content      string       `mapstructure:"content"`
	Sections     sections     `mapstructure:"sections"`
	Output       output       `mapstructure:"output"`
	OutputValues outputvalues `mapstructure:"output-values"`
	Sort         sort         `mapstructure:"sort"`
	Settings     settings     `mapstructure:"settings"`

	ModuleRoot string
}

Config represents all the available config options that can be accessed and passed through CLI.

func DefaultConfig added in v0.16.0

func DefaultConfig() *Config

DefaultConfig returns new instance of Config with default values set.

func NewConfig added in v0.16.0

func NewConfig() *Config

NewConfig returns neew instancee of Config with empty values.

func ReadConfig added in v0.16.0

func ReadConfig(rootDir string, filename string) (*Config, error)

ReadConfig reads config file in `rootDir` with given `filename` and returns instance of Config. It returns error if config file not found or there is a problem with unmarshalling.

func (*Config) Parse added in v0.16.0

func (c *Config) Parse()

Parse process config and set sections visibility.

func (*Config) Validate added in v0.16.0

func (c *Config) Validate() error

Validate provided Config and check for any misuse or misconfiguration.

Jump to

Keyboard shortcuts

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