shell

package
v0.15.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2024 License: Apache-2.0 Imports: 8 Imported by: 177

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EqualEnvKeys

func EqualEnvKeys(from, to string) bool

EqualEnvKeys compare two strings and returns true if they are equal. On Unix this comparison is case-sensitive. On Windows this comparison is case-insensitive.

func NormalizeEnvKey added in v0.15.0

func NormalizeEnvKey(key string) string

NormalizeEnvKey returns the key in a normalized form that can be used for comparison. On Unix this is a no-op. On Windows this converts the key to uppercase.

Types

type EnvGetter added in v0.15.0

type EnvGetter interface {
	Get(string) (string, bool)
	Keys() []string
}

func EnvsFromSlice added in v0.15.0

func EnvsFromSlice(env []string) EnvGetter

type Lex

type Lex struct {
	RawQuotes         bool
	RawEscapes        bool
	SkipProcessQuotes bool
	SkipUnsetEnv      bool
	// contains filtered or unexported fields
}

Lex performs shell word splitting and variable expansion.

Lex takes a string and an array of env variables and process all quotes (" and ') as well as $xxx and ${xxx} env variable tokens. Tries to mimic bash shell process. It doesn't support all flavors of ${xx:...} formats but new ones can be added by adding code to the "special ${} format processing" section

It is not safe to call methods on a Lex instance concurrently.

func NewLex

func NewLex(escapeToken rune) *Lex

NewLex creates a new Lex which uses escapeToken to escape quotes.

func (*Lex) ProcessWord

func (s *Lex) ProcessWord(word string, env EnvGetter) (string, map[string]struct{}, error)

ProcessWord will use the 'env' list of environment variables, and replace any env var references in 'word'. It will also return variables in word which were not found in the 'env' list, which is useful in later linting. TODO: rename

func (*Lex) ProcessWordWithMatches added in v0.10.0

func (s *Lex) ProcessWordWithMatches(word string, env EnvGetter) (ProcessWordResult, error)

ProcessWordWithMatches will use the 'env' list of environment variables, replace any env var references in 'word' and return the env that were used.

func (*Lex) ProcessWords

func (s *Lex) ProcessWords(word string, env EnvGetter) ([]string, error)

ProcessWords will use the 'env' list of environment variables, and replace any env var references in 'word' then it will also return a slice of strings which represents the 'word' split up based on spaces - taking into account quotes. Note that this splitting is done **after** the env var substitutions are done. Note, each one is trimmed to remove leading and trailing spaces (unless they are quoted", but ProcessWord retains spaces between words.

type ProcessWordResult added in v0.14.0

type ProcessWordResult struct {
	Result    string
	Words     []string
	Matched   map[string]struct{}
	Unmatched map[string]struct{}
}

Jump to

Keyboard shortcuts

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