Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
DefaultScriptGenerator = NewTemporaryScriptGenerator()
)
Functions ¶
func Run ¶
Run takes a set of options and executes the named program and its arguments.
A caller can specify a custom function that executes the exec.Command via [RunOptions.Exec]. This option is useful to mock calls during tests. The code falls back to a default implementation if [RunOptions.Exec] is nil.
Types ¶
type CachingScriptGenerator ¶ added in v0.42.0
type CachingScriptGenerator struct {
Wrap ScriptGenerator
// contains filtered or unexported fields
}
CachingScriptGenerator caches generated script files to reduce filesystem IO. It offloads the generation of the script files to a wrapped ScriptGenerator.
func NewCachingScriptGenerator ¶ added in v0.42.0
func NewCachingScriptGenerator(wrap ScriptGenerator) *CachingScriptGenerator
NewCachingScriptGenerator returns an initialized CachingScriptGenerator.
func (*CachingScriptGenerator) Clean ¶ added in v0.42.0
func (c *CachingScriptGenerator) Clean() error
Clean deletes all files previously cached.
func (*CachingScriptGenerator) Create ¶ added in v0.42.0
func (c *CachingScriptGenerator) Create(commands ...string) (string, error)
Create implements ScriptGenerator. The commands are hashed to create a cache key. It is not safe to call this function from multiple Goroutines.
func (*CachingScriptGenerator) Remove ¶ added in v0.42.0
func (c *CachingScriptGenerator) Remove(_ string) error
Remove implements ScriptGenerator.
It is a noop. Call CachingScriptGenerator.Clean to delete all files from the cache.
type Exec ¶
Exec is a function the executes cmd. It returns the exit code of the command and an error, if an error occurred.
type RunOptions ¶
type RunOptions struct {
// The current working directory of the command.
Dir string
// Environment variables of the command.
Env []string
// The function that executes the command.
Exec Exec
// Timeout of the command.
Timeout time.Duration
}
RunOptions are options accepted by Run.
type ScriptGenerator ¶ added in v0.42.0
type ScriptGenerator interface {
// Create takes a list of commands, writes them to a script file
// and returns the absolute path to the file.
// It returns an error if creating the file or writing to it fails.
Create(commands ...string) (string, error)
// Remove deletes the script file identified by name.
Remove(name string) error
}
A ScriptGenerator defines functions to create and remove a script file.
func NewTemporaryScriptGenerator ¶ added in v0.42.0
func NewTemporaryScriptGenerator() ScriptGenerator
NewTemporaryScriptGenerator returns a ScriptGenerator that writes commands to a temporary script file.
type ScriptOptions ¶
type ScriptOptions struct {
RunOptions
// A function to write a list of commands to a file.
// It returns the absolute path to the file on success.
ScriptGenerator ScriptGenerator
// Path to the shell that executes the script.
Shell string
}
ScriptOptions are options accepted by Script.