Documentation
¶
Index ¶
- Variables
- func GlobMatch(pattern, data string) (bool, error)
- func GlobMatchInfo(pattern string, info os.FileInfo) (bool, error)
- func GlobMatchName(pattern string, namer Namer) (bool, error)
- func Quote(argv []string) string
- func Substitute(s string, vars VariableMap) (string, error)
- type Glob
- type GlobError
- type Namer
- type SimpleVariableMap
- type VariableMap
Constants ¶
This section is empty.
Variables ¶
var (
ErrUnterminatedClass = errors.New("unterminated character class")
)
Functions ¶
func GlobMatchInfo ¶
GlobMatch compiles pattern, and then returns Glob.MatchInfo(info).
func GlobMatchName ¶
GlobMatch compiles pattern, and then returns Glob.MatchName(namer).
func Quote ¶
Quote returns a bash command approximating what a human would probably type to invoke the given argv array. For example, Quote([]string{"rm", "abc def", "hij"}) returns "rm 'abc def' hij".
func Substitute ¶
func Substitute(s string, vars VariableMap) (string, error)
Substitute expands and substitutes shell variables in s, and returns the fully substituted string. It errors out if s contains variables that do not exist in the specified variable map.
The syntax for variable substitution is a restricted variant to that of a POSIX shell:
- Variables are denoted with ${variable_name}.
- All characters except ":" and "}" are accepted in variable names.
- ${variable:-default} expands to "default" if the variable is not defined in the variable map, or the value of the variable otherwise.
- ${variable:+alternate} expands to "alternate" if the variable is defined in the variable map, or the empty string otherwise.
- ${variable/re/subst/} expands to the variable, with a regexp replacement. for instance, ${variable/^([^:]*):/\1/}, where variable=foo:bar, expands to foo.
If the passed VariableMap implements CanSubstitute(key string) bool, then the method is called to determine whether the variable is to be substituted. If the method returns false, the variable is left untouched and is output as-is into the result.
Types ¶
type Glob ¶
type Glob struct {
// contains filtered or unexported fields
}
Glob represents a compiled glob pattern. The supported syntax is mostly the same as glob(7), with the following extensions:
- Curly brace expansion is supported. "{a,b,c}" matches the strings "a", "b", and "c".
- A double star ("**") is supported to match any pathname component and their children. For instance, "dir/*" matches "dir/file" but not "dir/dir/file", while "dir/**" matches both.
- If the pattern starts with "!", the whole pattern is negated. If "!" appears later in the pattern, it is treated as a literal "!".
func CompileGlob ¶
CompileGlob compiles the specified pattern into a Glob object.
See the documentation of the Glob type for more details on the supported syntax.
func MustCompileGlob ¶
MustCompileGlob is like CompileGlob, but panics if the function returned an error.
func (*Glob) MarshalText ¶
func (*Glob) MatchInfo ¶
Match returns whether the specified FileInfo matches the glob pattern.
Generally, the name of the FileInfo is checked against the pattern. If the FileInfo represents a directory, the name followed by "/" is also checked against the pattern.
This behaviour allows for a pattern like "*/" to *only* match directories. If this is not desirable, use MatchName instead.
func (*Glob) MatchName ¶
Match returns whether the specified Namer matches the glob pattern. It is equivalent to Match(namer.Name()).
This function is there for convenience as both *os.File and os.FileInfo implement Name().
func (*Glob) UnmarshalText ¶
type GlobError ¶
type GlobError struct {
// Pattern is the erroneous glob pattern.
Pattern string
// Index is the index where the invalid character resides.
Index int
// Err is the concrete underlying error.
Err error
}
GlobError represents a syntax error for a specific glob pattern.
type Namer ¶
type Namer interface {
Name() string
}
A Namer represents types that have a Name. Notable types that implement this interface are *os.File and os.FileInfo.
type SimpleVariableMap ¶
SimpleVariableMap is a thin wrapper around map[string]string that implements VariableMap.
type VariableMap ¶
VariableMap is the interface that wraps the Get method.
Get takes a variable name, and returns the value associated to the variable if it has one, along with whether the variable is present in the variable map or not.