ctl

package
v0.0.0-...-b7a57f2 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Start    = Signal(0x71)
	Stop     = Signal(syscall.SIGSTOP)
	Restart  = Signal(0x70)
	Shutdown = Signal(syscall.SIGINT)
)

Variables

View Source
var ErrDone = fmt.Errorf("commander is done and can't be started")
View Source
var ErrInProgress = fmt.Errorf("in progress")

Functions

This section is empty.

Types

type Builder

type Builder interface {
	Build(context.Context) error
}

type Command

type Command interface {
	Name() string

	Start() error
	Stop() error
	Restart() error
	Running() bool

	Shutdown() error
	Done() <-chan struct{}

	Stdout() io.Reader
	Stderr() io.Reader
	Stdin() io.Writer
}

type CommandTree

type CommandTree interface {
	Command
	Subcommands() []Command
}

type Commander

type Commander interface {
	CommandTree
}

func NewCommander

func NewCommander(ctx context.Context, builder Builder, ctls ...Command) Commander

NewCommander creates a commander object which can be started and stopped until shutdown is called, then it becomes noop.

The commander allows it to control multiple commands while taking orders from a higher level instance like a TUI.

TODO: Could be benficial for a TUI to directly control the commands.

     That needs somehow blocking of a starting/stopping of the whole commander
     while a child is doing some work. This is currently not implemented.
     It is possible to control the underlying commands directly through
     `Subcommands()` but that could probably lead to nasty start/stop loops.
___________             ___________             ___________

| | Command() | | Command() | | | n*command | *-------1 | commander |1--------1 | tui | | | | | | | |___________| |___________| |___________|

type Control

type Control interface {
	Command

	Control() <-chan Signal

	EmitDone()
	EmitStopped()
	EmitStarted()
	EmitRestarted()
	EmitError(error)
}

func New

func New(name string, bufferedctl int, stdout, stderr io.Reader, stdin io.Writer) Control

New takes the size of the control channel. Usually this should be 0 so that signals are ignored as long as a start/stop is in progress.

type Flag

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

flag symbols a busy process with the possibility to be called from multiple goroutines multiple times.

func (*Flag) InProgress

func (f *Flag) InProgress() (done func(), err error)

InProgress aquires the flag if not set. Safe for parallel use. The caller is responsible to call done in case no error is returned.

type Signal

type Signal syscall.Signal

signal summary for internal use

Jump to

Keyboard shortcuts

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