expander

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package expander provides an extension for representing expandable expressions in command line arguments. The main use case is for dynamically evaluating these expressions with values that occur during the execution of the evaluators.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fprint

func Fprint(w io.Writer, pattern *Pattern, e Interface) (count int, err error)

Types

type ErrUnknownToken

type ErrUnknownToken string

func (ErrUnknownToken) Error

func (e ErrUnknownToken) Error() string

type Func

type Func func(string) any

Func converts the given string key into its variable expansion

func (Func) Expand

func (f Func) Expand(key string) any

type Interface

type Interface interface {
	Expand(key string) any
}

Interface converts the given string key into its variable expansion

func Colors

func Colors() Interface

func Compose

func Compose(expanders ...Interface) Interface

func Env

func Env() Interface

func Prefix

func Prefix(p string, e Interface) Interface

Prefix provides an expander which looks for and cuts a given prefix and delegates the result to the underlying expander

func Reflect added in v0.12.0

func Reflect(v any) Interface

Reflect provides a simple expander around a given value using reflection

func Time

func Time(t time.Time) Interface

Time obtains an expander for the specified time

func Unknown

func Unknown() Interface

type Map

type Map map[string]any

func (Map) Expand

func (m Map) Expand(k string) any

type Pattern

type Pattern struct {
	// contains filtered or unexported fields
}

func Compile

func Compile(pattern string) *Pattern

func CompilePattern

func CompilePattern(pattern, start, end string) *Pattern

func (*Pattern) Expand

func (p *Pattern) Expand(expand Interface) string

func (*Pattern) String

func (p *Pattern) String() string

func (*Pattern) WithMeta

func (p *Pattern) WithMeta(name string, pattern *Pattern) *Pattern

type Renderer

type Renderer struct {
	io.Writer
	// contains filtered or unexported fields
}

Renderer is a specialized writer that understands writing to multiple files and the corresponding variable support

func NewRenderer

func NewRenderer(stdout, stderr io.Writer) *Renderer

type Syntax

type Syntax int
const (
	// SyntaxDefault indicates that the expression syntax uses the
	// form <name>[':' <format>]. That is, an optional format string is allowed
	// to control the output.
	SyntaxDefault Syntax = iota

	// SyntaxRecursive causes recursive expression evaluation to
	// be allowed. For example, the expression ${VISUAL:${EDITOR}}
	// would evaluate both environment variables, falling back to EDITOR.
	SyntaxRecursive
)

func (Syntax) Compile

func (s Syntax) Compile(pattern string) *Pattern

func (Syntax) CompilePattern

func (s Syntax) CompilePattern(pattern, start, end string) *Pattern

Jump to

Keyboard shortcuts

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