stencil

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2020 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package stencil implements a template package manager.

Index

Constants

View Source
const MaxFileSize = 1000000

MaxFileSize specifies the max file size in the cache.

Variables

This section is empty.

Functions

func BaseDir added in v0.0.2

func BaseDir() (string, error)

func Untar added in v0.0.2

func Untar(src io.Reader, visit func(string, func() io.ReadCloser) error) error

Untar visits all files in a tar archive.

func Unzip added in v0.0.2

func Unzip(src io.Reader, visit func(string, func() io.ReadCloser) error) error

Unzip visits all files in a zip archive.

Types

type Binary added in v0.0.2

type Binary struct {
	*Stencil
}

Binary implements managing binaries.

func (*Binary) CopyFromArchive added in v0.0.2

func (b *Binary) CopyFromArchive(key, destination, url, file string) error

CopyFromArchive copies a file from an archive at the url. CopyFromArchive supports .tar, .tar.gz and .zip extensions for the archive.

func (*Binary) CopyManyFromArchive added in v0.0.2

func (b *Binary) CopyManyFromArchive(key, destination, url, glob string) error

CopyManyFromArchive extracts multiple files from an archive at the url. CopyManyFromArchive supports .tar, .tar.gz and .zip extensions for the archive. The glob pattern can be used to specify what files need to be extracted. See https://github.com/bmatcuk/doublestar for the set of allowed glob patterns. The destination is considered a folder.

type ConsolePrompt added in v0.0.2

type ConsolePrompt struct {
	Stdin  io.Reader
	Stdout io.Writer
}

ConsolePrompt implements the prompter interface.

func (*ConsolePrompt) PromptBool added in v0.0.2

func (c *ConsolePrompt) PromptBool(prompt string) (bool, error)

Bool prompts for and fetches a bool.

func (*ConsolePrompt) PromptString added in v0.0.2

func (c *ConsolePrompt) PromptString(prompt string) (string, error)

String prompts for and fetches a string.

type Env added in v0.0.2

type Env struct{}

Env implements some standard environent accessors for stencil.

func (Env) Arch added in v0.0.2

func (e Env) Arch() string

Arch returns runtime.GOARCH.

func (Env) OS added in v0.0.2

func (e Env) OS() string

OS returns runtime.GOOS.

type FS

type FS struct {
	BaseDir         string
	Verbose, Errorl Logger
}

FS implements a FileSystem interface.

func (*FS) Read

func (fs *FS) Read(path string) ([]byte, error)

Read reads the contents of the path and returns them as bytes.

func (*FS) Remove added in v0.0.2

func (fs *FS) Remove(path string) error

Remove removes a file.

func (*FS) RemoveAll added in v0.0.2

func (fs *FS) RemoveAll(path string) error

RemoveAll removes a directory and all its contents.

func (*FS) Resolve added in v0.0.2

func (fs *FS) Resolve(path string) (string, error)

Resolve pins a git path to a specific hash/commit.

func (*FS) Write

func (fs *FS) Write(path string, data []byte, mode os.FileMode) error

Write saves a file within the local directory.

type FileArchiveObj added in v0.0.2

type FileArchiveObj struct {
	Many           bool
	Loc, URL, File string
}

FileArchiveObj tracks an archive.

type FileObj added in v0.0.2

type FileObj struct {
	Loc, URL string
}

FileObj tracks a single file copied locally.

type FileSystem

type FileSystem interface {
	Read(path string) ([]byte, error)
	Write(path string, data []byte, mode os.FileMode) error
	Remove(path string) error
	RemoveAll(path string) error
}

FileSystem is the generic file system used by stencil. Use FS{} or a custom implementation.

type Logger

type Logger interface {
	Printf(format string, v ...interface{})
}

Logger is the interface used by stencil to log messages.

Use log.New(...) to create an appropriate logger.

type Markdown added in v0.0.2

type Markdown struct {
	*Stencil
}

Markdown implements the markdown functionality.

func (*Markdown) CopyMarkdownSnippets added in v0.0.2

func (m *Markdown) CopyMarkdownSnippets(key, localPath, url, regex string) error

CopyMarkdownSnippets first treats the url as a markdown stripping out everything but code fences with names matching the provided regex. The name of the code fence is the first word after the triple backquote.

Note that standard go templates are still executed on top of this so the embedded code can use any stencil function.

func (*Markdown) FilterMarkdown added in v0.0.2

func (m *Markdown) FilterMarkdown(data, regex string) (string, error)

type Objects added in v0.0.2

type Objects struct {
	*Stencil     `json:"-"`
	Before       *Objects `json:"-"`
	Pulls        map[string]bool
	Files        map[string]*FileObj
	FileArchives map[string]*FileArchiveObj
	Bools        map[string]bool
	Strings      map[string]string
}

Objects tracks a collection of objects

func (*Objects) GC added in v0.0.2

func (o *Objects) GC() error

GC removes any files and dirs that are no longer active.

func (*Objects) LoadObjects added in v0.0.2

func (o *Objects) LoadObjects() error

LoadObjects loads all the objects from the .stencil directory.

func (*Objects) SaveObjects added in v0.0.2

func (o *Objects) SaveObjects() error

SaveObjects saves all the objects to the .stencil directory.

type Prompter added in v0.0.2

type Prompter interface {
	PromptBool(prompt string) (bool, error)
	PromptString(prompt string) (string, error)
}

Prompter is the generic interface to prompt and fetch info interactively.

type Stencil

type Stencil struct {
	State  map[string]interface{}
	Funcs  map[string]interface{}
	Printf func(format string, v ...interface{})
	Errorf func(format string, v ...interface{}) error
	FileSystem
	Prompter
	Env
	Binary
	Objects
	Vars
	Markdown
}

Stencil maintains all the state for managing a single directory.

func New

func New(verbose, errorl Logger, p Prompter, fs FileSystem) *Stencil

New creates a new stencil manager.

func (*Stencil) CopyFile

func (s *Stencil) CopyFile(key, localPath, url string) error

CopyFile copies a url to a local file.

func (*Stencil) Execute added in v0.0.2

func (s *Stencil) Execute(source string) (string, error)

Execute is like Run but it returns the output.

func (*Stencil) Import

func (s *Stencil) Import(source string) (string, error)

Import imports a template after applying it.

func (*Stencil) Main

func (s *Stencil) Main(f *flag.FlagSet, args []string) error

Main implements the main program.

func (*Stencil) Run

func (s *Stencil) Run(source string) error

Run runs a template discarding the output.

type Vars

type Vars struct {
	*Stencil

	BoolDefs   map[string]string
	StringDefs map[string]string
	// contains filtered or unexported fields
}

Vars holds named values.

func (*Vars) DefineBool

func (v *Vars) DefineBool(name, prompt string) error

DefineBool defines a boolean variable name.

func (*Vars) DefineString added in v0.0.2

func (v *Vars) DefineString(name, prompt string) error

DefineString defines a string variable name.

func (*Vars) Init added in v0.0.2

func (v *Vars) Init(f *flag.FlagSet)

Init initializes vars. Must be calleed for flag.Parse.

func (*Vars) VarBool

func (v *Vars) VarBool(name string) (bool, error)

VarBool fetches the value for the named boolean. If the value is not present either via --var or via a previous invocation, the value is prompted for using the prompt in the definition. Any --var use overrides default values present from previous invocations.

func (*Vars) VarString added in v0.0.2

func (v *Vars) VarString(name string) (string, error)

VarString fetches the value for the named variable. If the value is not present either via --var or via a previous invocation, the value is prompted for using the prompt in the definition. Any --var use overrides default values present from previous invocations.

Jump to

Keyboard shortcuts

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