commands

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

package commands provides the interfaces and structures to trigger and run shell commands.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoCmd = fmt.Errorf("cmd provided without a command configured; fix it")
)

Errors produced by this file.

Functions

This section is empty.

Types

type Action

type Action struct {
	// contains filtered or unexported fields
}

Action contains the exported methods for this package.

func New

func New(config *common.Config, commands []*Command) *Action

New configures the library.

func (*Action) Create

func (a *Action) Create()

Create initializes the library.

func (*Action) GetByHash

func (a *Action) GetByHash(hash string) *Command

GetByHash returns a command by the hash ID.

func (*Action) List

func (a *Action) List() []*Command

List returns a list of active triggers that can be executed.

type Command

type Command struct {
	Name    string        `json:"name" toml:"name" xml:"name" yaml:"name"`
	Command string        `json:"-" toml:"command" xml:"command" yaml:"command"`
	Shell   bool          `json:"shell" toml:"shell" xml:"shell" yaml:"shell"`
	Log     bool          `json:"log" toml:"log" xml:"log" yaml:"log"`
	Notify  bool          `json:"notify" toml:"notify" xml:"notify" yaml:"notify"`
	Timeout cnfg.Duration `json:"-" toml:"timeout" xml:"timeout" yaml:"timeout"`
	Hash    string        `json:"hash" toml:"-" xml:"-" yaml:"-"`
	// contains filtered or unexported fields
}

Command contains the input data for a defined command. It also contains some saved data about the command being run.

func (*Command) Run

func (c *Command) Run(event website.EventType)

Run fires a custom command.

func (*Command) RunNow

func (c *Command) RunNow(ctx context.Context, event website.EventType) (string, error)

RunNow runs the command immediately, waits for and returns the output.

func (*Command) Setup

func (c *Command) Setup(logger mnd.Logger, website *website.Server)

Setup must run in the creation routine.

func (*Command) Stats

func (c *Command) Stats() Stats

Stats returns statistics about a command.

type Stats

type Stats struct {
	Runs       int    `json:"runs"`
	Fails      int    `json:"fails"`
	LastOutput string `json:"output"`
	LastRun    string `json:"last"`
}

Stats for a command's invocations.

Jump to

Keyboard shortcuts

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