Documentation
¶
Overview ¶
Package processrunner contains functionality for running a set of commands or other processes during generation, such as target-specific compilation or testing.
Index ¶
- Constants
- type Command
- type CommandDependency
- type CommandVersionDependency
- type Dependencies
- type Runner
- func (r Runner) CheckDependencies(ctx context.Context, dir string, argVars map[string]string) (string, error)
- func (r Runner) Run(ctx context.Context, dir string, argVars map[string]string) (string, error)
- func (r Runner) RunCommands(ctx context.Context, dir string, argVars map[string]string) (string, string, error)
Constants ¶
const ( ErrDependencyNotFound = generatorErrors.Error("dependency not found") ErrDependencyVersion = generatorErrors.Error("dependency version not met") )
const CanceledCommandWaitDelay = 100 * time.Millisecond
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct {
// Command name.
Command string
// Arguments to pass to the command.
//
// If runtime argument variables are given, each argument is ran through
// [text/template] to enable variable substition. For example, templating
// an Example variable via {{ .Example }} anywhere in the string.
//
// Available variables are:
//
// - PackageVersion: Generator selected new version for target.
//
// It is highly recommended add any templating variables in the runner
// dependencies to prevent confusing errors.
Args []string
// Mapping of environment variable names to values for overriding.
EnvironmentVariables map[string]string
// When enabled, return without error if the command is not found. This
// allows optional tooling commands to be ran, but only if present.
IgnoreCommandNotFound bool
// When enabled, discards stdout output.
StdoutDiscard bool
// When enabled, consecutive commands with Parallel set to true will be
// ran concurrently. All parallel commands in a group must complete before
// the next non-parallel command runs.
Parallel bool
}
An individual command to be ran.
type CommandDependency ¶
type CommandDependency struct {
// Command name.
Command string
// Documentation about how to install the command.
InstallDocumentation string
// Verify the dependency version.
Version *CommandVersionDependency
}
An individual command dependency.
type CommandVersionDependency ¶
type CommandVersionDependency struct {
// Arguments to pass to the command to retrieve the version.
Args []string
// Minimum supported version for the command.
MinimumVersion *version.Version
// Regular expression to extract the version for the command.
Pattern *regexp.Regexp
}
Command version dependency verification.
type Dependencies ¶
type Dependencies struct {
// Mapping of required argument variables names to value regular expressions
// for argument templating.
ArgVariables map[string]*regexp.Regexp
// Required commands.
Commands []CommandDependency
// Mapping of required environment variable names to value regular
// expressions.
EnvironmentVariables map[string]*regexp.Regexp
}
Dependencies for the runner commands.
type Runner ¶
type Runner struct {
// The commands to run, if dependencies are met.
Commands []Command
// Command dependency verification, before running the commands. Repeated
// commands only require a single dependency.
Dependencies Dependencies
}
A set of commands to be ran by the generator, such as target-specific compilation and testing commands.
func (Runner) CheckDependencies ¶
func (r Runner) CheckDependencies(ctx context.Context, dir string, argVars map[string]string) (string, error)
Verifies the Runner is prepared to run the commands by checking the dependencies.
func (Runner) Run ¶
Checks dependencies and runs all processes. Use other methods, such as CheckDependencies and RunCommands, for additional control if necessary.
func (Runner) RunCommands ¶
func (r Runner) RunCommands(ctx context.Context, dir string, argVars map[string]string) (string, string, error)
Runs the commands. Consecutive commands with Parallel set to true are ran concurrently as a group. All commands in a parallel group must complete before the next non-parallel command runs. Errors from parallel commands are collected and joined.