conf

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Delimiters []string   `yaml:"delimiters"`
	Copy       *bool      `yaml:"copy"`
	Ignore     *bool      `yaml:"ignore"`
	Variables  *Variables `yaml:"variables"`
	If         string     `yaml:"if"`
	Ctx        InputCtx   `yaml:"-"`
}

Config is a configuration that can be applied to a single file (inline conf) or to an entire directory

type ConfigFile

type ConfigFile struct {
	Config `yaml:",inline"`
	File   *File `yaml:"-"`
}

ConfigFile is the combination of File and Config

func NewConfigFile

func NewConfigFile(path string, file os.FileInfo, ctx InputCtx) *ConfigFile

NewConfigFile returns a new configfile

func (*ConfigFile) Parse

func (c *ConfigFile) Parse() error

Parse parses the configuration file

func (*ConfigFile) Prompt

func (c *ConfigFile) Prompt()

Prompt will prompt the necessary prompts wihtout displaying the ones for variables that were already defined in the input file

type File

type File struct {
	Path      string
	Dir       string
	NewPath   string
	Info      os.FileInfo
	Renderers []*ConfigFile
	Metadata  *FileMetadata
	Ctx       InputCtx
}

File represents a single file, combining both its path and its os.FileInfo

func NewFile

func NewFile(path string, file os.FileInfo, ctx InputCtx) *File

NewFile returns a new file

func (*File) AddRenderer

func (f *File) AddRenderer(c *ConfigFile)

AddRenderer adds a renderer to a file

func (*File) ParseFrontMatter

func (f *File) ParseFrontMatter() error

ParseFrontMatter will parse the front matter and add a renderer to the file if needed

func (*File) Render

func (f *File) Render() error

Render will actually render the file

func (*File) WriteCopy

func (f *File) WriteCopy() error

WriteCopy will write the file to its intended path and not attempt to render

func (*File) WriteRender

func (f *File) WriteRender(ctx map[string]interface{}, delims []string) error

WriteRender will first render the file as if ignored, but will parse it and render it as soon as it has been copied

type FileMetadata added in v1.4.0

type FileMetadata struct {
	Config `yaml:",inline"`
	Rename string `yaml:"rename"`
}

type InputCtx

type InputCtx yaml.MapSlice

InputCtx is the input context

func GetInputContext

func GetInputContext(path string) (InputCtx, error)

GetInputContext will return a map of string to interface{} that will then be used to determine whether or not a value from the root config file has already been filled

func GetSetContext

func GetSetContext(set []string) (InputCtx, error)

GetSetContext will return the map of string to interface{} that contains the set flags passed on the command line parsed

func MergeCtx

func MergeCtx(a, b InputCtx) InputCtx

MergeCtx will merge two InputCtx into a single one

type Root

type Root struct {
	ConfigFile  `yaml:",inline"`
	Name        string `yaml:"name"`
	Version     string `yaml:"version"`
	Description string `yaml:"description"`
}

Root is a ConfigFile with extra information. It should be located at the root of the template

func NewRootConfig

func NewRootConfig(path string, file os.FileInfo, ctx InputCtx) *Root

NewRootConfig will return the root configuration

func (Root) NewPath

func (r Root) NewPath(f *File, new string)

NewPath adds the path where the file should be rendered according to the root

func (*Root) Parse

func (r *Root) Parse() error

Parse will parse the yaml file and store its result in the root config

type Variable

type Variable struct {
	// Default value to display to the user for input prompts
	Default string `yaml:"default"`

	// Prompt allows to override the standard prompt and display more info
	CustomPrompt string `yaml:"prompt"`

	// List of possible values for the user to answer
	Values []string `yaml:"values"`

	// If this field isn't empty, then an help message can be shown to the user
	Help string `yaml:"help"`

	// Flags a variable as required, preventing the user from entering empty
	// values
	Required bool `yaml:"required"`

	// Confirm is used both for default variable and to store the result.
	// If this field isn't nil, then a confirmation survey is used.
	Confirm   *bool     `yaml:"confirm,omitempty"`
	Variables Variables `yaml:"variables,omitempty"`

	Result string
	Name   string
}

Variable represents a single variable

func (*Variable) FillFromMapItem

func (v *Variable) FillFromMapItem(i yaml.MapItem)

FillFromMapItem fills the value not from prompt but from a mapitem

func (*Variable) FromMapItem

func (v *Variable) FromMapItem(i yaml.MapItem)

FromMapItem will fill the variable with the data stored in the input yaml.MapItem. Used to recursively parse nested variables.

func (*Variable) Prompt

func (v *Variable) Prompt()

Prompt prompts for the variable

func (*Variable) True

func (v *Variable) True() bool

True returns if the variable has been filled

type Variables

type Variables []*Variable

Variables is a slice of pointer to a single variable

func (Variables) AddToCtx

func (vv Variables) AddToCtx(prefix string, ctx map[string]interface{})

AddToCtx will add the variable results to a sub-key

func (Variables) Ctx

func (vv Variables) Ctx() map[string]interface{}

Ctx generates the context from the variables

func (*Variables) FillPrompt

func (vv *Variables) FillPrompt(prefix string, ctx InputCtx)

FillPrompt will fill the variables from the input context if needed

func (Variables) FindNamed

func (vv Variables) FindNamed(s string) *Variable

FindNamed will find a variable by name in the global variables. Returns nil if not found

func (Variables) FindWithParent

func (vv Variables) FindWithParent(p *Variable, s string) *Variable

FindWithParent tries to find the variable with a prefix

func (*Variables) FromMapSlice

func (vv *Variables) FromMapSlice(in yaml.MapSlice)

FromMapSlice fills in the Variables struct with the data stored in a yaml.MapSlice. Used to recursively parse nested variables.

func (Variables) Prompt

func (vv Variables) Prompt()

Prompt will prompt

func (*Variables) UnmarshalYAML

func (vv *Variables) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML defines a custom way to unmarshal to the Variables type. Specifically this allows to conserve the key order

Jump to

Keyboard shortcuts

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