cmdsync

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd

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

Cmd is a wrapper around exec.Cmd that eases syncing to other Cmd's via Group.

Its implementation calls the shell directly (through zsh/bash)

Cmd can indicate that the underlying process has reached a "ready state" by

  1. Its stdout/stderr outputs matching a given regexp.
  2. Its underlying process completing/exiting with a non-zero code.

An interrupt signal can be sent to the underlying process via Interrupt().

func NewCmd

func NewCmd(shell, command string, options ...CmdOption) (*Cmd, error)

NewCmd defaults to using zsh. bash and sh are also supported

func (*Cmd) Interrupt

func (c *Cmd) Interrupt() error

Interrupt will send an interrupt signal to the process

func (*Cmd) IsReady

func (c *Cmd) IsReady() bool

IsReady is a simple getter for the ready state of a monitored command

func (*Cmd) Run

func (c *Cmd) Run() error

Run the underlying command. This function blocks until the command exits

func (*Cmd) Write

func (c *Cmd) Write(in []byte) (int, error)

Write implements io.Writer, so that Cmd itself can be used for exec.Cmd.Stdout and Stderr Write "intercepts" writes to Stdout/Stderr to check if the outputs match a regexp and determines if a command has reached its "ready state" the ready state is used by Orchestrator to coordinate dependent commands

type CmdOption

type CmdOption func(*Cmd) error

func CmdDir

func CmdDir(dir string) CmdOption

CmdDir is a functional option that modifies the Dir property of the underlying exec.Cmd which is the directory to execute the Command from

func CmdName

func CmdName(name string) CmdOption

CmdName is a functional option that sets a monitored command's name, which is used to prefix each line written to Stdout

func DependsOn

func DependsOn(cmdNames []string) CmdOption

DependsOn is a functional option that sets a slice of dependencies for this command. The dependencies are names of commands that need to have completed or reached a ready state prior to this command starting.

Note that there is no validation that the cmdNames are valid/match other Cmd's configs (because it would cause a circular dependency). Some, but not all possible config errors are checked at runtime.

func Environment

func Environment(envMap map[string]string) CmdOption

Environment is a functional option that adds export commands to the start of a command. This is a bit of a hacky workaround to maintain exec.Cmd's default environment, while being able to set additional variables

func ReadyPattern

func ReadyPattern(pattern string) CmdOption

ReadyPattern is a functional option that takes in a pattern string that must compile into a valid regexp and sets it to monitored command's readyPattern field

func SetColor

func SetColor(terminalColor string) CmdOption

SetColor is a functional option that sets the ansiColor for the outputs

func SilenceOutput

func SilenceOutput() CmdOption

SilenceOutput sets the command's Stdout and Stderr to nil so no output will be seen in the terminal

type Group

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

Group manages scheduling concurrent Cmds

func NewGroup

func NewGroup(commands ...*Cmd) *Group

NewGroup makes a new Group it can be optionally initialized with commands or they can be added later via AddCommands

func (*Group) AddCommands

func (g *Group) AddCommands(commands ...*Cmd) error

AddCommands will add Cmds to the commands slice It will return an error if called after Group.Run()

func (*Group) Run

func (g *Group) Run(ctx context.Context) error

Run will run all of the group's Cmds and block until they have all finished running, or an interrupt/kill signal is received, or the context cancels

It checks for each Cmd's prerequisites (Cmds it depends-on being in a ready state) before starting the Cmd

The returned error is the first error returned from the Group's Cmds, if any

func (*Group) SendInterrupts

func (g *Group) SendInterrupts()

SendInterrupts relays an interrupt signal to all underlying commands

Jump to

Keyboard shortcuts

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