cmdgrouper

package
v2.0.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package cmdgrouper provides types for grouping together commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

type Group struct {
	Start    api.CmdID
	End      api.CmdID
	Name     string
	UserData interface{}
}

Group is the product of a Grouper.

type Grouper

type Grouper interface {
	// Process considers the command for inclusion in the group.
	Process(context.Context, api.CmdID, api.Cmd, *api.GlobalState)
	// Build returns the groups built and resets the state of the grouper.
	Build(end api.CmdID) []Group
}

Grouper is the interface implemented by types that build groups.

func Marker

func Marker() Grouper

Marker returns a grouper that groups based on user marker commands.

func Run

func Run(pred RunPred) Grouper

Run returns a grouper that groups commands together that form a run.

func Sequence

func Sequence(name string, rules ...Rule) Grouper

Sequence returns a Grouper that groups commands that match a sequence of rules.

type Rule

type Rule struct {
	// Pred returns true if the rule passes.
	Pred func(cmd, prev api.Cmd) bool
	// Repeats is true if the rule should repeat until it no longer passes.
	// The rule has to pass at least once for the sequence to complete.
	Repeats bool
	// Optional is true if the rule can be skipped and still have the sequence
	// complete.
	Optional bool
}

Rule is a single rule in a sequence grouper.

type RunPred

type RunPred func(cmd api.Cmd, s *api.GlobalState) (value interface{}, name string)

RunPred is the predicate used by the Run grouper. Consecutive values returned by RunPred will be grouped together under the group with name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL