action

package
v0.0.0-...-edc17b4 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action interface {
	Run(ctx context.Context, t Target, args Arguments) (string, error)
	String() string
}

Action represents an action that can be applied.

The Run method applies the action to a given target and returns a string describing the result.

Actions should not mutate themselves or have side effects since they are intended to be run multiple times with different targets, possible on different goroutines.

The String method provides a string description of the action.

func Parse

func Parse(cfg Config) (Action, error)

Parse parses a config that describes an action and returns an Action.

type Arguments

type Arguments struct {
	// Values for variables that can be expanded during actions.
	Variables map[string]string
}

Arguments contains additional arguments that can be provided when running an Action.

type Config

type Config struct {
	// Identifies the type of action. Required for all actions.
	Type string `yaml:"type"`

	// The text to search for in a text action.
	SearchText string `yaml:"searchText"`
	// The text to apply in a text action.
	ApplyText string `yaml:"applyText"`
	// The path to the file in a text file.
	// Must be relative to the target root.
	Path string `yaml:"path"`

	// The source file to use in a file action.
	SrcPath string `yaml:"srcPath"`
	// The destination file to use in a file action.
	// Must be relative to the target root.
	DstPath string `yaml:"dstPath"`

	// The command to run in a command action.
	Run string `yaml:"run"`
}

Config is used to configure an action. It is passed to Parse to create an Action instance.

type Target

type Target interface {
	Path() string
}

Target represents an item that an Action will be applied to.

Jump to

Keyboard shortcuts

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