execute

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: MIT Imports: 13 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// AnsiblePlaybookErrorCodeGeneralError is the error code for a general error
	AnsiblePlaybookErrorCodeGeneralError = 1
	// AnsiblePlaybookErrorCodeOneOrMoreHostFailed is the error code for a one or more host failed
	AnsiblePlaybookErrorCodeOneOrMoreHostFailed = 2
	// AnsiblePlaybookErrorCodeOneOrMoreHostUnreachable is the error code for a one or more host unreachable
	AnsiblePlaybookErrorCodeOneOrMoreHostUnreachable = 3
	// AnsiblePlaybookErrorCodeParserError is the error code for a parser error
	AnsiblePlaybookErrorCodeParserError = 4
	// AnsiblePlaybookErrorCodeBadOrIncompleteOptions is the error code for a bad or incomplete options
	AnsiblePlaybookErrorCodeBadOrIncompleteOptions = 5
	// AnsiblePlaybookErrorCodeUserInterruptedExecution is the error code for a user interrupted execution
	AnsiblePlaybookErrorCodeUserInterruptedExecution = 99
	// AnsiblePlaybookErrorCodeUnexpectedError is the error code for a unexpected error
	AnsiblePlaybookErrorCodeUnexpectedError = 250

	// AnsiblePlaybookErrorMessageGeneralError is the error message for a general error
	AnsiblePlaybookErrorMessageGeneralError = "ansible-playbook error: general error"
	// AnsiblePlaybookErrorMessageOneOrMoreHostFailed is the error message for a one or more host failed
	AnsiblePlaybookErrorMessageOneOrMoreHostFailed = "ansible-playbook error: one or more host failed"
	// AnsiblePlaybookErrorMessageOneOrMoreHostUnreachable is the error message for a one or more host unreachable
	AnsiblePlaybookErrorMessageOneOrMoreHostUnreachable = "ansible-playbook error: one or more host unreachable"
	// AnsiblePlaybookErrorMessageParserError is the error message for a parser error
	AnsiblePlaybookErrorMessageParserError = "ansible-playbook error: parser error"
	// AnsiblePlaybookErrorMessageBadOrIncompleteOptions is the error message for a bad or incomplete options
	AnsiblePlaybookErrorMessageBadOrIncompleteOptions = "ansible-playbook error: bad or incomplete options"
	// AnsiblePlaybookErrorMessageUserInterruptedExecution is the error message for a user interrupted execution
	AnsiblePlaybookErrorMessageUserInterruptedExecution = "ansible-playbook error: user interrupted execution"
	// AnsiblePlaybookErrorMessageUnexpectedError is the error message for a unexpected error
	AnsiblePlaybookErrorMessageUnexpectedError = "ansible-playbook error: unexpected error"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Commander

type Commander interface {
	Command() ([]string, error)
	String() string
}

Commander generates commands to be executed

type DefaultExecute

type DefaultExecute struct {
	// Cmd is the command generator
	Cmd Commander
	// CmdRunDir specifies the working directory of the command.
	CmdRunDir string
	// EnvVars specifies env vars of the command.
	EnvVars EnvVars
	// ErrContext is the error context
	ErrorEnrich ErrorEnricher
	// Exec is the executor
	Exec Executabler
	// Output manages the output of the command
	Output result.ResultsOutputer

	// Transformers is the list of transformers func for the output
	Transformers []transformer.TransformerFunc
	// Writer is where is written the command stdout
	Write io.Writer
	// WriterError is where is written the command stderr
	WriterError io.Writer
	// contains filtered or unexported fields
}

DefaultExecute is a simple definition of an executor

func NewDefaultExecute

func NewDefaultExecute(options ...ExecuteOptions) *DefaultExecute

NewDefaultExecute return a new DefaultExecute instance with all options

func (*DefaultExecute) AddEnvVar

func (e *DefaultExecute) AddEnvVar(key, value string)

AddEnvVar add the provided environment variable. It overwrites the variable when it already exists.

func (*DefaultExecute) AddEnvVarSafe

func (e *DefaultExecute) AddEnvVarSafe(key, value string) error

AddEnvVarSafe add the provided environment variable. It returns an error when the variable already exists

func (*DefaultExecute) Execute

func (e *DefaultExecute) Execute(ctx context.Context) (err error)

Execute takes a command and args and runs it, streaming output to stdout

func (*DefaultExecute) Quiet

func (e *DefaultExecute) Quiet()

Quiet sets the executor in quiet mode

func (*DefaultExecute) WithOutput

func (e *DefaultExecute) WithOutput(output result.ResultsOutputer)

WithOutput sets the output mechanism to DefaultExecutor

type EnvVars

type EnvVars map[string]string

EnvVars represents a custom environment for an ansible playbook execution.

func (EnvVars) Environ

func (e EnvVars) Environ() []string

Environ returns a copy of strings representing the custom environment, in the form "key=value".

type ErrorEnricher

type ErrorEnricher interface {
	Enrich(err error) error
}

ErrorEnricher interface to enrich and customize errors

type Executabler

type Executabler interface {
	Command(name string, arg ...string) exec.Cmder
	CommandContext(ctx context.Context, name string, arg ...string) exec.Cmder
}

Executabler is an interface to run commands

type ExecuteOptions

type ExecuteOptions func(*DefaultExecute)

ExecuteOptions is a function to set executor options

func WithCmd

func WithCmd(cmd Commander) ExecuteOptions

WithCmd set the execuctable parameter

func WithCmdRunDir

func WithCmdRunDir(cmdRunDir string) ExecuteOptions

WithCmdRunDir set the command run directory to be used by DefaultExecutor

func WithEnvVars

func WithEnvVars(vars map[string]string) ExecuteOptions

WithEnvVars adds the provided env var to the command

func WithErrorEnrich

func WithErrorEnrich(enricher ErrorEnricher) ExecuteOptions

WithErrorEnrich sets the error context mechanism to DefaultExecutor

func WithExecutable

func WithExecutable(executable Executabler) ExecuteOptions

WithExecutable set the execuctable parameter

func WithOutput

func WithOutput(output result.ResultsOutputer) ExecuteOptions

WithOutput sets the output mechanism to DefaultExecutor

func WithTransformers

func WithTransformers(trans ...transformer.TransformerFunc) ExecuteOptions

WithTransformers set trasformes functions

func WithWrite

func WithWrite(w io.Writer) ExecuteOptions

WithWrite set the writer to be used by DefaultExecutor

func WithWriteError

func WithWriteError(w io.Writer) ExecuteOptions

WithWriteError set the error writer to be used by DefaultExecutor

type Executor

type Executor interface {
	Execute(ctx context.Context) error
}

Executor interface to execute commands

type MockExecute

type MockExecute struct {
	mock.Mock
}

MockExecute is a mock of Execute interface

func NewMockExecute

func NewMockExecute() *MockExecute

NewMockExecute returns a new instance of MockExecute

func (*MockExecute) AddEnvVar

func (e *MockExecute) AddEnvVar(key, value string)

AddEnvVar is a mock

func (*MockExecute) Execute

func (e *MockExecute) Execute(ctx context.Context) error

Execute is a mock

func (*MockExecute) Quiet

func (e *MockExecute) Quiet()

Quiet is a mock

func (*MockExecute) WithOutput

func (e *MockExecute) WithOutput(output result.ResultsOutputer)

WithOutput is a mock

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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