clitool

package
v0.0.0-...-c2e338f Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2020 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgOpt

type ArgOpt func(args *Args)

ArgOpt is a functional option setting fields within Args once executed.

func BoolFlag

func BoolFlag(key string, b bool) ArgOpt

func Combine

func Combine(opts ...ArgOpt) ArgOpt

func Env

func Env(key, value string) ArgOpt

func EnvIf

func EnvIf(key, value string) ArgOpt

func Extra

func Extra(key, value string) ArgOpt

func ExtraIf

func ExtraIf(key, value string) ArgOpt

func Flag

func Flag(key, value string) ArgOpt

func FlagIf

func FlagIf(key, value string) ArgOpt

func Noop

func Noop() ArgOpt

func Positional

func Positional(values ...string) ArgOpt

func SetIf

func SetIf(fn func(k, v string) ArgOpt, key, value string) ArgOpt

func When

func When(b bool, opt ArgOpt) ArgOpt

type Args

type Args struct {
	// Extra flags one can pass to a go command wrapper.
	Extra map[string]string

	// Environment variables to set when calling a go command.
	Environment map[string]string

	// Flags sets the CLI flags to be passed
	Flags []CommandFlag

	// Positional configured positional arguments
	Positional []string
}

Args holds parameters, environment variables and flag information used to pass to the go tool.

func CreateArgs

func CreateArgs(opts ...ArgOpt) *Args

func (*Args) Add

func (a *Args) Add(p string)

Add adds a positional argument to be passed to the child process on exec.

func (*Args) Build

func (a *Args) Build() []string

func (*Args) GetExtra

func (a *Args) GetExtra(k string) string

GetExtra reads some value from 'extra' fields.

func (*Args) GetExtraDefault

func (a *Args) GetExtraDefault(k, d string) string

GetExtraDefault reads a value from 'extra' fields. Returns 'd' if the key is missing.

func (*Args) SetEnv

func (a *Args) SetEnv(k, v string)

SetEnv sets an environmant variable to be passed to the child process on exec.

func (*Args) SetExtra

func (a *Args) SetExtra(k, v string)

SetExtra sets a 'special' value

func (*Args) SetFlag

func (a *Args) SetFlag(flag, value string)

SetFlag sets an environment variable flag.

type CLIExecutor

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

CLIExecutor runs a command with arguments using the os.Exec function.

func NewCLIExecutor

func NewCLIExecutor(verbose bool) *CLIExecutor

func (*CLIExecutor) Exec

func (e *CLIExecutor) Exec(
	ctx context.Context,
	c Command,
	args *Args,
	stdout, stderr io.Writer,
) (bool, error)

func (*CLIExecutor) ExecCollectOutput

func (e *CLIExecutor) ExecCollectOutput(
	ctx context.Context,
	c Command,
	args *Args,
) (string, error)

type Command

type Command struct {
	Path       string
	SubCommand []string
	WorkingDir string
}

func (*Command) Exec

func (c *Command) Exec(
	ctx context.Context,
	args *Args,
	stdout, stderr io.Writer,
) (bool, error)

func (*Command) ExecCollectOutput

func (c *Command) ExecCollectOutput(
	ctx context.Context,
	args *Args,
) (string, error)

type CommandFlag

type CommandFlag struct {
	Key   string
	Value string
}

type Executor

type Executor interface {
	Exec(
		ctx context.Context,
		cmd Command,
		args *Args,
		stdout, stderr io.Writer,
	) (bool, error)
}

Jump to

Keyboard shortcuts

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