command

package
v0.0.0-...-e537141 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Packege environment implements setting up and handling environment variables.

Any varible implementing the Formatter interface can be set as value to Map.

Example usage:

envMap := environment.Map{
    "OS": environemnt.String("linux"),
    "GOLANG": environment.True,
    "CORES": environment.Int(6),
}

env := envMap.IntoEnv()
// converted to environment.Env the result is
// env = {}string{"OS=linux", "GOLANG", "CORES=6"}

// alternatively the Map above could be created like so:
envMap := make(environment.Map)

envMap.Set("OS", "linux")
envMap.Use("GOLANG")
envMap.SetInt("CORES", 6)

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{
	Env:    EmptyEnv,
	Stdin:  os.Stdin,
	Stdout: os.Stdout,
	Stderr: os.Stderr,
}
View Source
var EmptyEnv = NewEnvironment(emptySlice)

EmptyEnv is an environment with no values.

View Source
var NonZeroLen = MinimumLength(1)
View Source
var OsFsValidator = fs.Validated(fs.OS(), fs.TypeEnsurer(path.TypeFile))

Functions

func BatchExecute

func BatchExecute(ctx context.Context, split SplitFn, ex Executor, opt Options, r io.Reader) error

func Call

func Call(ctx context.Context, ex Executor, cmd string, args ...string) (s string, err error)

Call executes command named by cmd with args using the DefaultOptions.

func CallBackground

func CallBackground(ex Executor, cmd string, args ...string) (s string, err error)

func Run

func Run(ctx context.Context, ex Executor, cmd string, args ...string) error

func RunBackground

func RunBackground(ex Executor, cmd string, args ...string) error

func SetString

func SetString(s StringChecker, target *string, source string)

Types

type Builder

type Builder struct {
	Kind    ExecutorKind
	Logging bool
}

type Debug

type Debug struct {
	Out       io.Writer
	Formatter Formatter
}

func (Debug) Execute

func (d Debug) Execute(ctx context.Context, s Setup, op Options) (err error)

type DryRunner

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

func NewDryRunner

func NewDryRunner(fmter Formatter, w io.Writer) DryRunner

func (DryRunner) Execute

func (dr DryRunner) Execute(ctx context.Context, s Setup, opt Options) error

type Env

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

Env is a struct representing a set of environment values.

func From

func From(i Into) (e Env, err error)

From uses the implemented IntoEnv function to convert i into an Env variable.

func NewEnvironment

func NewEnvironment(env []string) (e Env)

NewEnvironment creates an Env out of a string slice.

func (Env) Get

func (e Env) Get() (s []string)

Get returns the string slice representing the set of environment variables.

type EnvFormatter

type EnvFormatter interface {
	// FormatEnv will return with the string representation of an environment
	// variable given a specific key.
	FormatEnv(key string) string
}

Formatter is the value type for Map.

var True EnvFormatter = trueVal{}

True represents that the environment variable is set.

type Executor

type Executor interface {
	Execute(context.Context, Setup, Options) error
}

type ExecutorJSON

type ExecutorJSON struct {
	Executor
}

func (*ExecutorJSON) UnmarshalJSON

func (e *ExecutorJSON) UnmarshalJSON(b []byte) (err error)

type ExecutorKind

type ExecutorKind int
const (
	KindStd ExecutorKind = iota
	KindDryRun
)

type FilesCheck

type FilesCheck interface {
	ExecuteCheck(Setup, Options) error
}

type Formatter

type Formatter interface {
	FormatCommand(io.Writer, Setup, Options) error
}
var LineFormat Formatter = (*LineFormatter)(nil)

type HasLength

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

func MinimumLength

func MinimumLength(minLen uint) (h HasLength)

func (HasLength) IsUpdateNeeded

func (h HasLength) IsUpdateNeeded(length int) (b bool)

func (HasLength) StringUpdateNeeded

func (h HasLength) StringUpdateNeeded(source string) (b bool)

type Int

type Int int

Int is an alias to int to implement the Formatter interface.

func (Int) FormatEnv

func (i Int) FormatEnv(key string) (out string)

FormatEnv implements the Formatter interface

type Into

type Into interface {
	IntoEnv() (Env, error)
}

Into represents any type that can be converted into an environment.Env variable.

type IsValidPath

type IsValidPath bool
const (
	PathValid    IsValidPath = true
	PathNotValid IsValidPath = false
)

func (IsValidPath) Match

func (vp IsValidPath) Match(e error) (err error)

type Lexer

type Lexer interface {
	Next() (string, error)
}

type LineFormatter

type LineFormatter struct{}

func (*LineFormatter) FormatCommand

func (*LineFormatter) FormatCommand(wr io.Writer, s Setup, op Options) (err error)

type Map

type Map map[string]EnvFormatter

Map represent key value pairs of environment variables

func (Map) IntoEnv

func (m Map) IntoEnv() (env Env, err error)

IntoEnv converts m into an Env

func (Map) Remove

func (m Map) Remove(key string)

Remove removes a key from the map.

func (Map) Set

func (m Map) Set(key, val string)

Set sets key to String(val).

func (Map) SetInt

func (m Map) SetInt(key string, val int)

SetInt sets key to Int(val).

func (Map) Use

func (m Map) Use(key string)

Use sets key to True.

type MultiExecutor

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

func Executors

func Executors(rep errors.Reporter, execs ...Executor) MultiExecutor

func (MultiExecutor) Execute

func (m MultiExecutor) Execute(ctx context.Context, setup Setup, opts Options) error

type MultiFormatter

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

func (MultiFormatter) FormatCommand

func (mf MultiFormatter) FormatCommand(wr io.Writer, s Setup, op Options) error

type NoOpExecute

type NoOpExecute struct{}

func NoOpExecutor

func NoOpExecutor() *NoOpExecute

func (NoOpExecute) Execute

type Options

type Options struct {
	Stdin       io.Reader
	Stdout      io.Writer
	Stderr      io.Writer
	SysProcAttr *syscall.SysProcAttr
	Dir         string
	ExtraFiles  []*os.File
	Env         Env
}

func CaptureOut

func CaptureOut(opt Options, w io.Writer) Options

func (Options) SetCmd

func (op Options) SetCmd(cmd *exec.Cmd)

type Setup

type Setup struct {
	Name string
	Args []string
}

type SharedEnv

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

func SharedEnvExecutor

func SharedEnvExecutor(ex Executor, env Env) (s SharedEnv)

func (SharedEnv) Execute

func (se SharedEnv) Execute(ctx context.Context, s Setup, op Options) error

type Shlex

type Shlex struct {
	Split    SplitFn
	NewLexer func(r io.Reader) Lexer
}

type SplitFn

type SplitFn func(s string) ([]string, error)

type StdExecutor

type StdExecutor struct{}

func NewStdExec

func NewStdExec() (s *StdExecutor)

func (StdExecutor) Execute

func (StdExecutor) Execute(ctx context.Context, s Setup, op Options) (err error)

type String

type String string

String is an alias to string to implement the Formatter interface.

func (String) FormatEnv

func (s String) FormatEnv(key string) (out string)

FormatEnv implements the Formatter interface

type StringChecker

type StringChecker interface {
	StringUpdateNeeded(source string) (needed bool)
}

type Token

type Token interface {
	Equal(Token) bool
}

type Tokenizer

type Tokenizer interface {
	Next() (Token, error)
}

type ValidMismatch

type ValidMismatch struct {
	IsValidPath
	// contains filtered or unexported fields
}

func (ValidMismatch) Error

func (vm ValidMismatch) Error() (s string)

func (ValidMismatch) Unwrap

func (vm ValidMismatch) Unwrap() (err error)

type Validator

type Validator interface {
	Validate(path.Like) error
}

type ValidatorTester

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

func NewValidatorTester

func NewValidatorTester(t *testing.T, val Validator) (vt ValidatorTester)

func (ValidatorTester) Expect

func (vt ValidatorTester) Expect(like path.Like, v IsValidPath) (err error)

Jump to

Keyboard shortcuts

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