bp

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2022 License: 0BSD Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BaseTemplate

func BaseTemplate() *template.Template

create a new template with extra functions

func CloneRepo

func CloneRepo(ctx context.Context, repo string) (path string, err error)

clone a git repo to the /tmp/<repo>, striping the .git suffix this has dependencies on the git binary

func CompileExcludes

func CompileExcludes(t *template.Template, excludes []Exclude, data *Data) ([]string, error)

check for each item in the exclude list if they should be included in the resulting string slice and append them to the slice if they do

func GetInput

func GetInput(key string, data map[string]any) (input any, err error)

get the user input from the terminal

func IsEmptyDir

func IsEmptyDir(name string) (bool, error)

func IsUpstreamRepo

func IsUpstreamRepo(path string) bool

checks if the given path is a git url

func LookupValue

func LookupValue(key string, data map[string]any) (value any, exists bool)

lookup nested values in a map by flat key path. i.e. foo.bar.baz if the map contains a dot, it must be escaped with a backslash

func MakeFsWalker

func MakeFsWalker(t *template.Template, data *Data, outPath string, excludeMatcher, rawMatcher Matcher, helpersFileName string) fs.WalkDirFunc

makeWalker returns a filepath.WalkFunc that renders all template found in the file tree with the given data and writes them to the output directory

func MergeMaps

func MergeMaps(maps ...map[string]any) map[string]any

merge all maps preferring values found later in the list

func NewFileMatcher

func NewFileMatcher(paths []string) (*fileMatcher, error)

func PathExists

func PathExists(path string) (bool, error)

func ReadFile

func ReadFile(path string, dist any) error

read the values from a file at the given path into dist

func ReadURL

func ReadURL(url string, dist any) error

read the values from the given url into dist

func ReadValues

func ReadValues(urlOrPath string, dist any) error

read the values from url or file into dist

func RenderString

func RenderString(t *template.Template, s string, data *Data) (string, error)

use the given template to parse and render the given string since this called template.Parse, the given string is associated with the template named templates are left intact

func RunHook

func RunHook(ctx context.Context, t *template.Template, chdir string, hook Hook, data *Data) error

run the given hook as shell command in the given directory the hook script is rendered as a template with the data before running it

Types

type BlueprintMeta

type BlueprintMeta struct {
	Input     []string  `json:"input,omitempty"`
	Exclude   []Exclude `json:"exclude,omitempty"`
	Raw       []string  `json:"raw,omitempty"`
	PreHooks  []Hook    `json:"preHooks,omitempty"`
	PostHooks []Hook    `json:"postHooks,omitempty"`
}

type Data

type Data struct {
	Project Project        `json:"project,omitempty"`
	Values  map[string]any `json:"values,omitempty"`
}

type Exclude

type Exclude struct {
	Pattern   string `json:"pattern,omitempty"`
	Condition string `json:"condition,omitempty"`
}

type Hook

type Hook struct {
	Name   string `json:"name,omitempty"`
	Script string `json:"script,omitempty"`
}

type Matcher

type Matcher interface {
	Match(string, os.FileInfo) bool
}

type Project

type Project struct {
	Name string `json:"name"`
}

Jump to

Keyboard shortcuts

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