shellUtils

package
v1.1.32 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ShellToUseUnix = "bash"
	ShellToUseWin  = "cmd"

	PowerShellCmd            = "powershell"
	PromptIgnoreSSG          = "PROMPT_IGNORE_SSG>"
	PowerShellPromptOverride = "function prompt { \"" + PromptIgnoreSSG + "\" }"
)

Variables

This section is empty.

Functions

func GetCommandPrimaryArgs added in v1.1.24

func GetCommandPrimaryArgs() []string

func GetCommandTargetRunner added in v1.1.24

func GetCommandTargetRunner() string

func GetGitStatsString

func GetGitStatsString() string

GetGitStats function will return the git stats in the following format: "d8e6e45 \n d8e6e45d52f7bf164a995e22abb81ffc6e3eeae1 \n 3 0"

func GetPowerShellPrimaryArgs added in v1.1.24

func GetPowerShellPrimaryArgs() []string

func GetPowerShellRunner added in v1.1.24

func GetPowerShellRunner() string

func StartProcess

func StartProcess(args ...string) (p *os.Process, err error)

Types

type ExecuteCommandConfig

type ExecuteCommandConfig struct {
	TargetRunner   string
	PrimaryArgs    []string
	Stdin          io.Reader
	Stdout         io.Writer
	Stderr         io.Writer
	AdditionalArgs []string
	AdditionalEnv  []string

	// ExtraFiles specifies additional open files to be inherited by the new process.
	// It does not include standard input, standard output, or standard error.
	// If non-nil, entry i becomes file descriptor 3+i.
	// ExtraFiles is not supported on Windows.
	ExtraFiles []*os.File

	FinishedChan chan bool

	// IsAsync field determines whether the command should be run
	// async or not. if this field is set to false, the execute
	// function will block the current goroutine until the process
	// ends completely.
	IsAsync                bool
	RemovePowerShellPrompt bool
	// contains filtered or unexported fields
}

type ExecuteCommandResult

type ExecuteCommandResult struct {
	// UniqueId is a unique id assigned to this execution result.
	// setting this field is up to the user and library itself won't
	// do anything with it.
	UniqueId string
	// Stdout field is the string representation of the output from
	// command. it's set only if you use `RunCommand` or `RunCommandAsync`
	// functions.
	Stdout string
	// Stderr field is the string representation of the err-output from
	// command. it's set only if you use `RunCommand` or `RunCommandAsync`
	// functions.
	Stderr string
	// Error field is set only after execution of the command finishes and
	// it can be nil.
	Error error
	// IsKilled field is set to true only if the `Kill` method is called.
	IsKilled     bool
	IsFinished   bool
	IsReleased   bool
	FinishedChan chan bool
	// contains filtered or unexported fields
}

func ExecuteCommand

func ExecuteCommand(command string, config *ExecuteCommandConfig) *ExecuteCommandResult

func ExecuteCommandAsync

func ExecuteCommandAsync(command string, config *ExecuteCommandConfig) *ExecuteCommandResult

func ExecutePowerShellAsync added in v1.1.24

func ExecutePowerShellAsync(command string, config *ExecuteCommandConfig) *ExecuteCommandResult

func RunCommand

func RunCommand(command string) *ExecuteCommandResult

func RunCommandAsync

func RunCommandAsync(command string) *ExecuteCommandResult

func RunCommandAsyncWithChan

func RunCommandAsyncWithChan(command string, finishedChan chan bool) *ExecuteCommandResult

func RunPowerShell added in v1.1.24

func RunPowerShell(command string) *ExecuteCommandResult

func RunPowerShellAsyncWithChan added in v1.1.24

func RunPowerShellAsyncWithChan(command string, finishedChan chan bool) *ExecuteCommandResult

func (*ExecuteCommandResult) ClosePipes added in v1.1.24

func (r *ExecuteCommandResult) ClosePipes() error

func (*ExecuteCommandResult) Exited

func (r *ExecuteCommandResult) Exited() bool

Exited reports whether the program has exited. On Unix systems this reports true if the program exited due to calling exit, but false if the program terminated due to a signal.

func (*ExecuteCommandResult) GetPurifiedPowerShellOutput added in v1.1.24

func (r *ExecuteCommandResult) GetPurifiedPowerShellOutput() string

func (*ExecuteCommandResult) IsDone

func (r *ExecuteCommandResult) IsDone() bool

func (*ExecuteCommandResult) Kill

func (r *ExecuteCommandResult) Kill() error

func (*ExecuteCommandResult) PurifyPowerShellOutput added in v1.1.24

func (r *ExecuteCommandResult) PurifyPowerShellOutput() string

PurifyOutput will purify the stdout of the result and will set the purified version of the output. If you just want to get the purified version without setting the new value, use

func (*ExecuteCommandResult) Release

func (r *ExecuteCommandResult) Release() error

func (*ExecuteCommandResult) UserTime

func (r *ExecuteCommandResult) UserTime() time.Duration

func (*ExecuteCommandResult) WaitAndRun

func (r *ExecuteCommandResult) WaitAndRun(
	interval, timeout time.Duration,
	handler ExecuteResultEventHandler,
)

WaitAndRun method waits for the execution to either finish or gets cancelled.

type ExecuteResultEventHandler

type ExecuteResultEventHandler func(result *ExecuteCommandResult)

type StdinWrapper added in v1.1.24

type StdinWrapper struct {
	InnerWriter io.WriteCloser

	OnWrite []func(p []byte) (n int, err error)
	OnClose []func() error
}

func (*StdinWrapper) Close added in v1.1.24

func (r *StdinWrapper) Close() error

func (*StdinWrapper) Write added in v1.1.24

func (r *StdinWrapper) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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