Documentation ¶
Overview ¶
Package otium allows incremental automation of manual procedures
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnrecoverable tells the REPL to exit. // // From client code, use the %w verb of fmt.Errorf: // func(bag otium.Bag) error { // return fmt.Errorf("failed to X... %w", otium.ErrUnrecoverable) // }, ErrUnrecoverable = errors.New("(unrecoverable)") )
Functions ¶
This section is empty.
Types ¶
type Bag ¶
type Bag struct {
// contains filtered or unexported fields
}
Bag is passed to the [RunFn] of Step. It contains all the k/v pairs added by the various steps during the execution of the otium Procedure.
func (*Bag) Get ¶
Get returns the value of key if key exists. If key doesn't exist, Get returns an error.
In case of error, it means that you didn't set the Variables field of Procedure.AddStep. See the examples for clarification.
type Procedure ¶
type Procedure struct { ProcedureOpts // contains filtered or unexported fields }
Procedure is made of a sequence of Step. Create it with NewProcedure, fill it with Procedure.AddStep and finally start it with Procedure.Execute.
func NewProcedure ¶
func NewProcedure(opts ProcedureOpts) *Procedure
NewProcedure creates a Procedure.
type ProcedureOpts ¶
type ProcedureOpts struct { // Name is the name of the Procedure; by default it is the name of the executable. Name string // Title is the title of the Procedure, shown at the beginning of the program. Title string // Desc is the summary of what the procedure is about, shown at the beginning of // the program, just after the Title. Desc string // PreFlight is an optional function run after the command-line has been parsed and // before the first step. // It is used to perform procedure-specific validations and to initialize the user // context. Such user context will then be passed as parameter uctx to each call // of Step.Run(bag Bag, uctx any). PreFlight func() (any, error) }
ProcedureOpts is used by NewProcedure to create a Procedure.
type Step ¶
type Step struct { // Title is the name of the step, shown in table of contents and at the // beginning of the step itself. Title string // Desc is the detailed description of what a human is supposed to do to // perform the step. If the step is automated, Desc should be shortened // and adapted to the change. Desc string // Vars are the new variables needed by the step. Vars []Variable // Run is the optional automation of the step. If the step is manual, // leave Run unset. When called, bag will contain all the key/value pairs // set by the previous steps and uctx, if not nil, will point to the user // context. // A typical Run will use [Bag.Get] to get a k/v, [Bag.Put] to put a k/v and // will type assert uctx to the type returned by [ProcedureOpts.PreFlight]. // For the user context, see also [ProcedureOpts.PreFlight] and // examples/usercontext. Run func(bag Bag, uctx any) error }
Step is part of a Procedure. See [Procedure.Add].
type ValidatorFn ¶ added in v0.1.2
ValidatorFn is the optional function to validate a k/v pair. It is called either when parsing the command-line or when processing the Vars field of a Step.