errcmd

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: MIT Imports: 14 Imported by: 11

Documentation

Index

Constants

View Source
const (
	InvalidExitCode         = constants.MinInt
	ScriptsMultiLineJoiner  = " && \\ \n" // " && \\ \n"
	SingleLineScriptsJoiner = " && "      // " && "

)

Variables

This section is empty.

Functions

func ArgsJoin added in v0.5.1

func ArgsJoin(args ...string) string

func ArgsJoinSlice added in v0.5.1

func ArgsJoinSlice(args []string) string

func ArgsJoinSlicePtr added in v0.5.1

func ArgsJoinSlicePtr(args *[]string) string

func BashArgsErrorWrapper added in v0.5.1

func BashArgsErrorWrapper(
	args ...string,
) *errorwrapper.Wrapper

func BashOutput added in v0.5.0

func BashOutput(
	scriptLines ...string,
) string

func BashScriptsErrorWrapper added in v0.5.2

func BashScriptsErrorWrapper(
	scriptLines ...string,
) *errorwrapper.Wrapper

func ChainCmdSuccess added in v0.5.0

func ChainCmdSuccess(
	scriptType scripttype.Variant,
	scriptLines ...string,
) (errorWrapper *errorwrapper.Wrapper, isAllSuccess bool)

ChainCmdSuccess if any script is failed to run then don't continue others

Returns true if scriptLines length 0

func ChangeDirScriptLine added in v0.5.2

func ChangeDirScriptLine(changeDirPath string) string

ChangeDirScriptLine cd path

func GetScriptOfChangeDirPlusScripts added in v0.5.2

func GetScriptOfChangeDirPlusScripts(changeDirPath string, scriptsLines ...string) string

GetScriptOfChangeDirPlusScripts cd path && \ \n scripts...

func IsBashArgsSuccess added in v0.5.1

func IsBashArgsSuccess(
	args ...string,
) bool

func IsBashScriptsSuccess added in v0.5.1

func IsBashScriptsSuccess(
	scriptLines ...string,
) bool

func IsShellArgsSuccess added in v0.5.1

func IsShellArgsSuccess(
	args ...string,
) bool

func IsShellScriptsSuccess added in v0.5.1

func IsShellScriptsSuccess(
	scriptLines ...string,
) bool

func IsSuccess added in v0.5.0

func IsSuccess(
	scriptType scripttype.Variant,
	scriptLines ...string,
) bool

func IsSuccessBashArgs added in v0.5.2

func IsSuccessBashArgs(
	args ...string,
) bool

func ShellArgsErrorWrapper added in v0.5.1

func ShellArgsErrorWrapper(
	args ...string,
) *errorwrapper.Wrapper

func ShellOutput added in v0.5.0

func ShellOutput(
	scriptLines ...string,
) string

func ShellScriptsErrorWrapper added in v0.5.1

func ShellScriptsErrorWrapper(
	scriptLines ...string,
) *errorwrapper.Wrapper

Types

type BaseBufferStdOutError

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

func (*BaseBufferStdOutError) CompiledErrorLines

func (receiver *BaseBufferStdOutError) CompiledErrorLines() *[]string

func (*BaseBufferStdOutError) CompiledOutputLines

func (receiver *BaseBufferStdOutError) CompiledOutputLines() *[]string

func (*BaseBufferStdOutError) CompiledTrimmedErrorLines

func (receiver *BaseBufferStdOutError) CompiledTrimmedErrorLines() *[]string

func (*BaseBufferStdOutError) CompiledTrimmedErrorOutput

func (receiver *BaseBufferStdOutError) CompiledTrimmedErrorOutput() *string

func (*BaseBufferStdOutError) CompiledTrimmedOutput

func (receiver *BaseBufferStdOutError) CompiledTrimmedOutput() *string

func (*BaseBufferStdOutError) CompiledTrimmedOutputLines

func (receiver *BaseBufferStdOutError) CompiledTrimmedOutputLines() *[]string

func (*BaseBufferStdOutError) ErrorBytes

func (receiver *BaseBufferStdOutError) ErrorBytes() *[]byte

func (*BaseBufferStdOutError) ErrorString

func (receiver *BaseBufferStdOutError) ErrorString() string

func (*BaseBufferStdOutError) HasErrorBuffer

func (receiver *BaseBufferStdOutError) HasErrorBuffer() bool

func (*BaseBufferStdOutError) HasOutputBuffer

func (receiver *BaseBufferStdOutError) HasOutputBuffer() bool

func (*BaseBufferStdOutError) OutputBytes

func (receiver *BaseBufferStdOutError) OutputBytes() *[]byte

func (*BaseBufferStdOutError) OutputString

func (receiver *BaseBufferStdOutError) OutputString() string

type BaseCmdWrapper

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

type CmdOnce

type CmdOnce struct {
	Cmd *exec.Cmd
	// contains filtered or unexported fields
}

func BashArgs added in v0.5.1

func BashArgs(
	args ...string,
) *CmdOnce

func BashChangeDirPlusRunArgs added in v0.5.2

func BashChangeDirPlusRunArgs(
	changeDirPath string,
	args ...string,
) *CmdOnce

func BashChangeDirPlusRunScripts added in v0.5.2

func BashChangeDirPlusRunScripts(
	changeDirPath string,
	scriptLines ...string,
) *CmdOnce

func BashScripts added in v0.5.1

func BashScripts(
	scriptLines ...string,
) *CmdOnce

func BashScriptsSingleLine added in v0.5.2

func BashScriptsSingleLine(
	changeDirPath string,
	scriptLines ...string,
) *CmdOnce

func ChangeDirPlusRunScriptsCmdOnce added in v0.5.2

func ChangeDirPlusRunScriptsCmdOnce(
	scriptType scripttype.Variant,
	changeDirPath string,
	scriptLines ...string,
) *CmdOnce

func NewCmdOnce

func NewCmdOnce(
	hasOutput,
	hasSecureData bool,
	process string,
	arguments ...string,
) *CmdOnce

func NewCmdOnceDefault

func NewCmdOnceDefault(
	process string,
	arguments ...string,
) *CmdOnce

func NewCmdOnceNoOutput

func NewCmdOnceNoOutput(
	process string,
	arguments ...string,
) *CmdOnce

func NewCmdOnceOutput

func NewCmdOnceOutput(
	process string,
	arguments ...string,
) *CmdOnce

func NewCmdOnceUsingCmd

func NewCmdOnceUsingCmd(
	hasOutput,
	hasSecureData bool,
	cmd *exec.Cmd,
) *CmdOnce

func NewCmdOnceUsingEmpty added in v0.5.0

func NewCmdOnceUsingEmpty() *CmdOnce

func NewCmdOnceUsingScriptType

func NewCmdOnceUsingScriptType(
	hasOutput,
	hasSecureData bool,
	scriptType scripttype.Variant,
	scriptLines ...string,
) *CmdOnce

func ScriptArgumentsDefault added in v0.5.1

func ScriptArgumentsDefault(
	scriptType scripttype.Variant,
	args ...string,
) *CmdOnce

func ScriptCmdOnceUsingArguments added in v0.5.1

func ScriptCmdOnceUsingArguments(
	hasOutput,
	hasSecureData bool,
	scriptType scripttype.Variant,
	args ...string,
) *CmdOnce

func ScriptsDefault added in v0.5.2

func ScriptsDefault(
	scriptType scripttype.Variant,
	scriptLines ...string,
) *CmdOnce

func ShellArgs added in v0.5.1

func ShellArgs(
	args ...string,
) *CmdOnce

func ShellScripts added in v0.5.1

func ShellScripts(
	scriptLines ...string,
) *CmdOnce

func (*CmdOnce) AddEnvVar

func (receiver *CmdOnce) AddEnvVar(
	varName, varValue string,
) *CmdOnce

AddEnvVar cannot add slice if already executed. Warning : panic if called after execution.

func (*CmdOnce) AddEnvVarKeyVal

func (receiver *CmdOnce) AddEnvVarKeyVal(keyVal corestr.KeyValuePair) *CmdOnce

AddEnvVarKeyVal cannot add slice if already executed. Warning : panic if called after execution.

func (*CmdOnce) AddEnvVarsHashmap

func (receiver *CmdOnce) AddEnvVarsHashmap(
	hashmap *corestr.Hashmap,
) *CmdOnce

AddEnvVarsHashmap cannot add slice if already executed. Warning : panic if called after execution.

func (*CmdOnce) AddEnvVarsSlice

func (receiver *CmdOnce) AddEnvVarsSlice(
	slice *[]string,
) *CmdOnce

AddEnvVarsSlice cannot add slice if already executed. Warning : panic if called after execution. Data needs to be in this format "MY_VAR=some_value"

func (*CmdOnce) Arguments

func (receiver *CmdOnce) Arguments() []string

func (*CmdOnce) ArgumentsSingleLine

func (receiver *CmdOnce) ArgumentsSingleLine() string

ArgumentsSingleLine Arguments Compiled using Space

func (*CmdOnce) Clone

func (receiver *CmdOnce) Clone() *CmdOnce

Clone calls constructor NewCmdOnce to create itself using the existing data.

func (*CmdOnce) CloneCmd

func (receiver *CmdOnce) CloneCmd(isUseStd bool) *exec.Cmd

CloneCmd Clones and creates a new cmd

If isUseStd true then it will clone it self and returns the cmd and buffer will be created and injected,

or else it will heavily depends on CompiledOutput or CombinedOutput

func (*CmdOnce) CommandLine

func (receiver *CmdOnce) CommandLine() string

CommandLine Gets commandline based on security. if receiver.hasSecureData then only returns process name

func (*CmdOnce) CompiledError

func (receiver *CmdOnce) CompiledError() string

CompiledError returns lazy once result.

Developer may check:

  • IsSuccessfullyExecuted() reveals if any issue after compile, thus runs the compile or RunOnce() first then returns bool. Or,
  • HasAnyIssues() reveals if any issue after compile, thus runs the compile or RunOnce() first then returns bool. Or,
  • isAlreadyRan() reveals already executed or not. Doesn't run the process. Or,
  • HasCmd() reveals if cmd is nil or not. Or,
  • HasIssues() reveals any issues before running cmd. Or,
  • CompiledErrorWrapper() to check the final error condition.

func (*CmdOnce) CompiledErrorBytes

func (receiver *CmdOnce) CompiledErrorBytes() *[]byte

CompiledErrorBytes returns lazy once result.

Developer may check:

  • IsSuccessfullyExecuted() reveals if any issue after compile, thus runs the compile or RunOnce() first then returns bool. Or,
  • HasAnyIssues() reveals if any issue after compile, thus runs the compile or RunOnce() first then returns bool. Or,
  • isAlreadyRan() reveals already executed or not. Doesn't run the process. Or,
  • HasCmd() reveals if cmd is nil or not. Or,
  • HasIssues() reveals any issues before running cmd. Or,
  • CompiledErrorWrapper() to check the final error condition.

func (*CmdOnce) CompiledErrorLines

func (receiver *CmdOnce) CompiledErrorLines() *[]string

CompiledErrorLines returns lazy once result.

Developer may check:

  • IsSuccessfullyExecuted() reveals if any issue after compile, thus runs the compile or RunOnce() first then returns bool. Or,
  • HasAnyIssues() reveals if any issue after compile, thus runs the compile or RunOnce() first then returns bool. Or,
  • isAlreadyRan() reveals already executed or not. Doesn't run the process. Or,
  • HasCmd() reveals if cmd is nil or not. Or,
  • HasIssues() reveals any issues before running cmd. Or,
  • CompiledErrorWrapper() to check the final error condition.

func (*CmdOnce) CompiledErrorWrapper

func (receiver *CmdOnce) CompiledErrorWrapper() *errorwrapper.Wrapper

func (*CmdOnce) CompiledOutput

func (receiver *CmdOnce) CompiledOutput() string

CompiledOutput returns lazy once result.

Developer may check:

  • IsSuccessfullyExecuted() reveals if any issue after compile, thus runs the compile or RunOnce() first then returns bool. Or,
  • HasAnyIssues() reveals if any issue after compile, thus runs the compile or RunOnce() first then returns bool. Or,
  • isAlreadyRan() reveals already executed or not. Doesn't run the process. Or,
  • HasCmd() reveals if cmd is nil or not. Or,
  • HasIssues() reveals any issues before running cmd. Or,
  • CompiledErrorWrapper() to check the final error condition.

func (*CmdOnce) CompiledOutputBytes

func (receiver *CmdOnce) CompiledOutputBytes() *[]byte

CompiledOutputBytes returns lazy once result.

Developer may check:

  • IsSuccessfullyExecuted() reveals if any issue after compile, thus runs the compile or RunOnce() first then returns bool. Or,
  • HasAnyIssues() reveals if any issue after compile, thus runs the compile or RunOnce() first then returns bool. Or,
  • isAlreadyRan() reveals already executed or not. Doesn't run the process. Or,
  • HasCmd() reveals if cmd is nil or not. Or,
  • HasIssues() reveals any issues before running cmd. Or,
  • CompiledErrorWrapper() to check the final error condition.

func (*CmdOnce) CompiledOutputLines

func (receiver *CmdOnce) CompiledOutputLines() *[]string

CompiledOutputLines returns lazy once result.

Developer may check:

  • IsSuccessfullyExecuted() reveals if any issue after compile, thus runs the compile or RunOnce() first then returns bool. Or,
  • HasAnyIssues() reveals if any issue after compile, thus runs the compile or RunOnce() first then returns bool. Or,
  • isAlreadyRan() reveals already executed or not. Doesn't run the process. Or,
  • HasCmd() reveals if cmd is nil or not. Or,
  • HasIssues() reveals any issues before running cmd. Or,
  • CompiledErrorWrapper() to check the final error condition.

func (*CmdOnce) CompiledResult

func (receiver *CmdOnce) CompiledResult() *Result

CompiledResult RunOnce and submits the compiled result structure.

func (*CmdOnce) CompiledTrimmedErrorLines

func (receiver *CmdOnce) CompiledTrimmedErrorLines() *[]string

CompiledTrimmedErrorLines returns lazy once result.

Developer may check:

  • IsSuccessfullyExecuted() reveals if any issue after compile, thus runs the compile or RunOnce() first then returns bool. Or,
  • HasAnyIssues() reveals if any issue after compile, thus runs the compile or RunOnce() first then returns bool. Or,
  • isAlreadyRan() reveals already executed or not. Doesn't run the process. Or,
  • HasCmd() reveals if cmd is nil or not. Or,
  • HasIssues() reveals any issues before running cmd. Or,
  • CompiledErrorWrapper() to check the final error condition.

func (*CmdOnce) CompiledTrimmedOutputLines

func (receiver *CmdOnce) CompiledTrimmedOutputLines() *[]string

CompiledTrimmedOutputLines returns lazy once result.

Developer may check:

  • IsSuccessfullyExecuted() reveals if any issue after compile, thus runs the compile or RunOnce() first then returns bool. Or,
  • HasAnyIssues() reveals if any issue after compile, thus runs the compile or RunOnce() first then returns bool. Or,
  • isAlreadyRan() reveals already executed or not. Doesn't run the process. Or,
  • HasCmd() reveals if cmd is nil or not. Or,
  • HasIssues() reveals any issues before running cmd. Or,
  • CompiledErrorWrapper() to check the final error condition.

func (*CmdOnce) DoubleQuoteWholeCommandLine

func (receiver *CmdOnce) DoubleQuoteWholeCommandLine() string

DoubleQuoteWholeCommandLine Process + Space + ArgumentsCompiledWithSpace

func (*CmdOnce) GetFormattedKeyValueData

func (receiver *CmdOnce) GetFormattedKeyValueData(
	varName string,
	varValue string,
) string

GetFormattedKeyValueData "MY_VAR=some_value"

func (*CmdOnce) HasAnyIssues

func (receiver *CmdOnce) HasAnyIssues() bool

HasAnyIssues executes run command and Gets the compile result and check if any compilation error Any issues include compile or cmd running error.

func (*CmdOnce) HasCmd

func (receiver *CmdOnce) HasCmd() bool

func (*CmdOnce) HasCompiledError

func (receiver *CmdOnce) HasCompiledError() bool

func (*CmdOnce) HasIssues

func (receiver *CmdOnce) HasIssues() bool

HasIssues reveals either cmd is nil or has any other cmd initialize error but it doesn't conclude running issues.

func (*CmdOnce) IsAlreadyRan

func (receiver *CmdOnce) IsAlreadyRan() bool

func (*CmdOnce) IsNull

func (receiver *CmdOnce) IsNull() bool

func (*CmdOnce) IsSuccessfullyExecuted

func (receiver *CmdOnce) IsSuccessfullyExecuted() bool

IsSuccessfullyExecuted Runs the execution and then returns the success result.

Reveals if any issue after compile, thus runs the compile or RunOnce() first then returns bool.

func (*CmdOnce) NewArgs

func (receiver *CmdOnce) NewArgs(additionalArgs ...string) *CmdOnce

func (*CmdOnce) ProcessName

func (receiver *CmdOnce) ProcessName() string

func (*CmdOnce) Run

func (receiver *CmdOnce) Run() *Result

Run non lazy and runs as many times called.

Warning: Costly operation, run it wisely.

Under the hood, it creates the same cmdOnce and call it's RunOnce.

func (*CmdOnce) RunOnce

func (receiver *CmdOnce) RunOnce() *Result

RunOnce only runs once the process and returns the cached data many times.

func (*CmdOnce) RunOnceWithSuccessFlag

func (receiver *CmdOnce) RunOnceWithSuccessFlag() (cmdResult *Result, isSuccess bool)

RunOnceWithSuccessFlag Runs the process then returns the isSuccess flag

func (*CmdOnce) String

func (receiver *CmdOnce) String() string

String()

If cmd is present and HasIssues false then it will call RunOnce and get the output and returns it.

func (*CmdOnce) WholeCommandLine

func (receiver *CmdOnce) WholeCommandLine() string

WholeCommandLine Process + Space + ArgumentsCompiledWithSpace

type Result

type Result struct {
	*BaseBufferStdOutError
	ExitError *exec.ExitError
	ExitCode  int
	// contains filtered or unexported fields
}

func BashArgsResult added in v0.5.1

func BashArgsResult(
	args ...string,
) *Result

func NewResult

func NewResult(
	errorWrapper *errorwrapper.Wrapper,
	stdOut, stdErr *bytes.Buffer,
	exitError *exec.ExitError,
	hasCommandExecuted bool,
) *Result

func NewResultUsingBaseBuffer

func NewResultUsingBaseBuffer(
	errorWrapper *errorwrapper.Wrapper,
	baseBuffer *BaseBufferStdOutError,
	exitError *exec.ExitError,
	hasCommandExecuted bool,
) *Result

func ShellArgsResult added in v0.5.1

func ShellArgsResult(
	args ...string,
) *Result

func ShellScriptsResult added in v0.5.1

func ShellScriptsResult(
	scriptLines ...string,
) *Result

func (*Result) DetailedOutput

func (receiver *Result) DetailedOutput() string

func (*Result) ErrorWrapper

func (receiver *Result) ErrorWrapper() *errorwrapper.Wrapper

func (*Result) HasCommandExecuted

func (receiver *Result) HasCommandExecuted() bool

func (*Result) HasError

func (receiver *Result) HasError() bool

func (*Result) HasExitError

func (receiver *Result) HasExitError() bool

func (*Result) IsEmptyError

func (receiver *Result) IsEmptyError() bool

func (*Result) IsExitCode

func (receiver *Result) IsExitCode(exitCode int) bool

func (*Result) IsInvalidExitCode

func (receiver *Result) IsInvalidExitCode() bool

func (*Result) String

func (receiver *Result) String() string

Jump to

Keyboard shortcuts

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