Documentation ¶
Overview ¶
Package goyek helps implementing build automation.
Example ¶
package main import ( "github.com/goyek/goyek" ) func main() { flow := &goyek.Flow{} task1 := flow.Register(goyek.Task{ Name: "task-1", Usage: "Print Go version", Action: func(tf *goyek.TF) { if err := tf.Cmd("go", "version").Run(); err != nil { tf.Fatal(err) } }, }) task2 := flow.Register(goyek.Task{ Name: "task-2", Action: func(tf *goyek.TF) { tf.Skip("skipping") }, }) task3 := flow.Register(goyek.Task{ Name: "task-3", Action: func(tf *goyek.TF) { tf.Error("hello from", tf.Name()) tf.Log("this will be printed") }, }) flow.Register(goyek.Task{ Name: "all", Deps: goyek.Deps{task1, task2, task3}, }) flow.Main() }
Output:
Index ¶
- Constants
- type BoolParam
- type Deps
- type Flow
- func (f *Flow) Main()
- func (f *Flow) Params() []RegisteredParam
- func (f *Flow) Register(task Task) RegisteredTask
- func (f *Flow) RegisterBoolParam(p BoolParam) RegisteredBoolParam
- func (f *Flow) RegisterIntParam(p IntParam) RegisteredIntParam
- func (f *Flow) RegisterStringParam(p StringParam) RegisteredStringParam
- func (f *Flow) RegisterValueParam(p ValueParam) RegisteredValueParam
- func (f *Flow) RegisterVerboseParam(p BoolParam) RegisteredBoolParam
- func (f *Flow) RegisterWorkDirParam(p StringParam) RegisteredStringParam
- func (f *Flow) Run(ctx context.Context, args ...string) int
- func (f *Flow) Tasks() []RegisteredTask
- func (f *Flow) VerboseParam() RegisteredBoolParam
- func (f *Flow) WorkDirParam() RegisteredStringParam
- type IntParam
- type ParamError
- type ParamValue
- type Params
- type RegisteredBoolParam
- type RegisteredIntParam
- type RegisteredParam
- type RegisteredStringParam
- type RegisteredTask
- type RegisteredValueParam
- type StringParam
- type TF
- func (tf *TF) Cmd(name string, args ...string) *exec.Cmd
- func (tf *TF) Context() context.Context
- func (tf *TF) Error(args ...interface{})
- func (tf *TF) Errorf(format string, args ...interface{})
- func (tf *TF) Fail()
- func (tf *TF) FailNow()
- func (tf *TF) Failed() bool
- func (tf *TF) Fatal(args ...interface{})
- func (tf *TF) Fatalf(format string, args ...interface{})
- func (tf *TF) Log(args ...interface{})
- func (tf *TF) Logf(format string, args ...interface{})
- func (tf *TF) Name() string
- func (tf *TF) Output() io.Writer
- func (tf *TF) Skip(args ...interface{})
- func (tf *TF) SkipNow()
- func (tf *TF) Skipf(format string, args ...interface{})
- func (tf *TF) Skipped() bool
- type Task
- type ValueParam
Examples ¶
Constants ¶
const ( // CodePass indicates that flow passed. CodePass = 0 // CodeFail indicates that flow failed. CodeFail = 1 // CodeInvalidArgs indicates that flow got invalid input. CodeInvalidArgs = 2 )
const ( // TaskNamePattern describes the regular expression a task name must match. TaskNamePattern = "^[a-zA-Z0-9_][a-zA-Z0-9:_+-]*$" // ParamNamePattern describes the regular expression a parameter name must match. ParamNamePattern = "^[a-zA-Z0-9][a-zA-Z0-9:_+-]*$" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Flow ¶ added in v0.6.0
type Flow struct { Output io.Writer // output where text is printed; os.Stdout by default DefaultTask RegisteredTask // task which is run when non is explicitly provided // contains filtered or unexported fields }
Flow is the root type of the package. Use Register methods to register all tasks and Run or Main method to execute provided tasks.
func (*Flow) Main ¶ added in v0.6.0
func (f *Flow) Main()
Main parses the command-line arguments and runs the provided tasks. The usage is printed when invalid arguments are passed.
func (*Flow) Params ¶ added in v0.6.0
func (f *Flow) Params() []RegisteredParam
Params returns all registered parameters.
func (*Flow) Register ¶ added in v0.6.0
func (f *Flow) Register(task Task) RegisteredTask
Register registers the task. It panics in case of any error.
func (*Flow) RegisterBoolParam ¶ added in v0.6.0
func (f *Flow) RegisterBoolParam(p BoolParam) RegisteredBoolParam
RegisterBoolParam registers a boolean parameter.
func (*Flow) RegisterIntParam ¶ added in v0.6.0
func (f *Flow) RegisterIntParam(p IntParam) RegisteredIntParam
RegisterIntParam registers an integer parameter.
func (*Flow) RegisterStringParam ¶ added in v0.6.0
func (f *Flow) RegisterStringParam(p StringParam) RegisteredStringParam
RegisterStringParam registers a string parameter.
func (*Flow) RegisterValueParam ¶ added in v0.6.0
func (f *Flow) RegisterValueParam(p ValueParam) RegisteredValueParam
RegisterValueParam registers a generic parameter that is defined by the calling code. Use this variant in case the primitive-specific implementations cannot cover the parameter.
The value is provided via a factory function since flow could be executed multiple times, requiring a new Value instance each time.
func (*Flow) RegisterVerboseParam ¶ added in v0.6.1
func (f *Flow) RegisterVerboseParam(p BoolParam) RegisteredBoolParam
RegisterVerboseParam overwrites the default name, usage and value for the verbose parameter. If this function is used, the default 'v' parameter will be replaced with this parameter.
func (*Flow) RegisterWorkDirParam ¶ added in v0.6.1
func (f *Flow) RegisterWorkDirParam(p StringParam) RegisteredStringParam
RegisterWorkDirParam overwrites the default name, usage and value for the work dir parameter. If this function is used, the default 'wd' parameter will be replaced with this parameter.
func (*Flow) Run ¶ added in v0.6.0
Run runs provided tasks and all their dependencies. Each task is executed at most once.
func (*Flow) Tasks ¶ added in v0.6.0
func (f *Flow) Tasks() []RegisteredTask
Tasks returns all registered tasks.
func (*Flow) VerboseParam ¶ added in v0.6.0
func (f *Flow) VerboseParam() RegisteredBoolParam
VerboseParam returns the out-of-the-box verbose parameter which controls the output behavior. This can be overridden with RegisterVerboseParam.
func (*Flow) WorkDirParam ¶ added in v0.6.0
func (f *Flow) WorkDirParam() RegisteredStringParam
WorkDirParam returns the out-of-the-box working directory parameter which controls the working directory.
type ParamError ¶
type ParamError struct { Key string // the parameter's key Err error // the reason the conversion failure, e.g. *strconv.NumError }
ParamError records an error during parameter conversion.
func (*ParamError) Error ¶
func (e *ParamError) Error() string
type ParamValue ¶
type ParamValue interface { // String returns the current value formatted as string. // The returned format should be in a single line, representing the parameter // as it could be provided on the command line. String() string // IsBool marks parameters that do not explicitly need to be set a value. // Set will be called in case the flag is not explicitly parameterized. IsBool() bool // Get returns the current value, properly typed. // Values must return their default value if Set() has not yet been called. Get() interface{} // Set parses the given string and sets the typed value. Set(string) error }
ParamValue represents an instance of a generic parameter.
type RegisteredBoolParam ¶
type RegisteredBoolParam struct {
// contains filtered or unexported fields
}
RegisteredBoolParam represents a registered boolean parameter.
func (RegisteredBoolParam) Default ¶ added in v0.6.0
func (p RegisteredBoolParam) Default() string
Default returns the parameter's default value formatted as string.
func (RegisteredBoolParam) Get ¶
func (p RegisteredBoolParam) Get(tf *TF) bool
Get returns the boolean value of the parameter in the given flow.
type RegisteredIntParam ¶
type RegisteredIntParam struct {
// contains filtered or unexported fields
}
RegisteredIntParam represents a registered integer parameter.
func (RegisteredIntParam) Default ¶ added in v0.6.0
func (p RegisteredIntParam) Default() string
Default returns the parameter's default value formatted as string.
func (RegisteredIntParam) Get ¶
func (p RegisteredIntParam) Get(tf *TF) int
Get returns the integer value of the parameter in the given flow.
type RegisteredParam ¶
type RegisteredParam interface { Name() string Usage() string Default() string // contains filtered or unexported methods }
RegisteredParam represents a parameter that has been registered to a Flow. It can be used as a parameter for a Task.
type RegisteredStringParam ¶
type RegisteredStringParam struct {
// contains filtered or unexported fields
}
RegisteredStringParam represents a registered string parameter.
func (RegisteredStringParam) Default ¶ added in v0.6.0
func (p RegisteredStringParam) Default() string
Default returns the parameter's default value formatted as string.
func (RegisteredStringParam) Get ¶
func (p RegisteredStringParam) Get(tf *TF) string
Get returns the string value of the parameter in the given flow.
type RegisteredTask ¶
type RegisteredTask struct {
// contains filtered or unexported fields
}
RegisteredTask represents a task that has been registered to a Flow. It can be used as a dependency for another Task.
func (RegisteredTask) Deps ¶ added in v0.6.0
func (r RegisteredTask) Deps() Deps
Deps returns the task's dependencies.
func (RegisteredTask) Name ¶ added in v0.6.0
func (r RegisteredTask) Name() string
Name returns the name of the task.
func (RegisteredTask) Params ¶ added in v0.6.0
func (r RegisteredTask) Params() Params
Params returns the task's parameters.
func (RegisteredTask) Usage ¶ added in v0.6.0
func (r RegisteredTask) Usage() string
Usage returns the description of the task.
type RegisteredValueParam ¶
type RegisteredValueParam struct {
// contains filtered or unexported fields
}
RegisteredValueParam represents a registered parameter based on a generic implementation.
func (RegisteredValueParam) Default ¶ added in v0.6.0
func (p RegisteredValueParam) Default() string
Default returns the parameter's default value formatted as string.
func (RegisteredValueParam) Get ¶
func (p RegisteredValueParam) Get(tf *TF) interface{}
Get returns the concrete instance of the generic value in the given flow.
type StringParam ¶
StringParam represents a named string parameter that can be registered.
type TF ¶
type TF struct {
// contains filtered or unexported fields
}
TF is a type passed to Task's Action function to manage task state.
A Task ends when its Action function returns or calls any of the methods FailNow, Fatal, Fatalf, SkipNow, Skip, or Skipf.
All methods must be called only from the goroutine running the Action function.
func (*TF) Cmd ¶
Cmd is like exec.Command, but it assigns tf's context and assigns Stdout and Stderr to tf's output, and Stdin to os.Stdin.
func (*TF) Error ¶
func (tf *TF) Error(args ...interface{})
Error is equivalent to Log followed by Fail.
func (*TF) Fail ¶
func (tf *TF) Fail()
Fail marks the function as having failed but continues execution.
func (*TF) FailNow ¶
func (tf *TF) FailNow()
FailNow marks the function as having failed and stops its execution by calling runtime.Goexit (which then runs all deferred calls in the current goroutine). It finishes the whole flow.
func (*TF) Fatal ¶
func (tf *TF) Fatal(args ...interface{})
Fatal is equivalent to Log followed by FailNow.
func (*TF) Log ¶
func (tf *TF) Log(args ...interface{})
Log formats its arguments using default formatting, analogous to Println, and prints the text to Output. A final newline is added. The text will be printed only if the task fails or flow is run in Verbose mode.
func (*TF) Logf ¶
Logf formats its arguments according to the format, analogous to Printf, and prints the text to Output. A final newline is added. The text will be printed only if the task fails or flow is run in Verbose mode.
func (*TF) Skip ¶
func (tf *TF) Skip(args ...interface{})
Skip is equivalent to Log followed by SkipNow.
func (*TF) SkipNow ¶
func (tf *TF) SkipNow()
SkipNow marks the task as having been skipped and stops its execution by calling runtime.Goexit (which then runs all deferred calls in the current goroutine). If a test fails (see Error, Errorf, Fail) and is then skipped, it is still considered to have failed. Flow will continue at the next task.
type Task ¶
type Task struct { // Name uniquely identifies the task. // Names may not be empty and should be easily representable on the CLI. Name string // Usage provides information what the task does. // If it is empty, this task will not be listed in the usage output. Usage string // Action executes the task in the given flow context. // A task can be registered without a action and can act as a "collector" task // for a list of dependencies. Action func(tf *TF) // Deps lists all registered tasks that need to be run before this task is executed. Deps Deps // Params is a list of registered parameters that the action may need during executions. // Not all parameters need to be queried during execution, yet accessing a parameter // that was not registered will fail the task. Params Params }
Task represents a named task that can be registered. It can consist of a action (function that will be called when task is run), dependencies (tasks which has to be run before this one) parameters (which can be used within the action).
type ValueParam ¶
type ValueParam struct { Name string Usage string NewValue func() ParamValue }
ValueParam represents a named parameter for a custom type that can be registered. NewValue field must be set with a default value factory.