cli

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CtxKeyQuiet = struct{ quiet bool }{/* contains filtered or unexported fields */}

CtxKeyQuiet is the context key to mute the chain.

View Source
var Settings = struct {
	// Verbose toggles verbose output for commands.
	Verbose bool
}{}

Settings is global cli settings

Functions

func Command

func Command(command string, args ...string) *exec.Cmd

Command creates a new command.

func CommandInteractive

func CommandInteractive(command string, args ...string) *exec.Cmd

CommandInteractive creates a new interactive command.

func ErrNonFatal added in v0.5.3

func ErrNonFatal(err error) error

ErrNonFatal creates a non-fatal error for a command chain. A warning would be printed instead of terminating the chain.

func Prompt

func Prompt(question string) bool

Prompt prompts for input with a question. It returns true only if answer is y or Y.

Types

type ActiveCommandChain

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

ActiveCommandChain is an active command chain.

func (*ActiveCommandChain) Add

func (a *ActiveCommandChain) Add(f func() error)

Add adds a new function to the runner.

func (ActiveCommandChain) Exec

func (a ActiveCommandChain) Exec() error

Exec executes the command chain. The first errored function terminates the chain and the error is returned. Otherwise, returns nil.

func (*ActiveCommandChain) Logger added in v0.6.0

func (a *ActiveCommandChain) Logger() *log.Entry

Logger returns the logger for the command chain.

func (*ActiveCommandChain) Retry added in v0.3.0

func (a *ActiveCommandChain) Retry(stage string, interval time.Duration, count int, f func(retryCount int) error)

Retry retries `f` up to `count` times at interval. If after `count` attempts there is an error, the command chain is terminated with the final error. retryCount starts from 1.

func (*ActiveCommandChain) Stage

func (a *ActiveCommandChain) Stage(s string)

Stage sets the current stage of the runner.

func (*ActiveCommandChain) Stagef

func (a *ActiveCommandChain) Stagef(format string, s ...interface{})

Stagef is like stage with string format.

type CommandChain

type CommandChain interface {
	// Init initiates a new runner using the current instance.
	Init(ctx context.Context) *ActiveCommandChain
	// Logger returns the instance logger.
	Logger(ctx context.Context) *log.Entry
}

CommandChain is a chain of commands. commands are executed in order.

func New

func New(name string) CommandChain

New creates a new runner instance.

Jump to

Keyboard shortcuts

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