exec

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd

type Cmd struct {
	*exec.Cmd
}

func Command

func Command(name string, arg ...string) *Cmd

func (*Cmd) Run

func (c *Cmd) Run(DONT_CALL_THIS string)

Probably a better way to do this, but it works for now!

type CmdResult

type CmdResult struct {
	StdErr string
	StdOut string
	Err    error
}

type CommandRunner

type CommandRunner func(cmd *Cmd) error
var Run CommandRunner = func(cmd *Cmd) error {
	return cmd.Cmd.Run()
}

type Executor

type Executor func(workDir string, args ...string) CmdResult
var Exec Executor = func(workDir string, args ...string) CmdResult {
	out.Debugln("Running Command: ", shellquote.Join(args...))
	cmd := exec.Command(args[0], args[1:]...)
	var stdoutBuf, stderrBuf bytes.Buffer
	cmd.Stderr = &stderrBuf
	cmd.Stdout = &stdoutBuf
	cmd.Dir = workDir
	err := cmd.Run()
	stderr := strings.TrimSpace(stderrBuf.String())
	stdout := strings.TrimSpace(stdoutBuf.String())
	out.Debugln("StdErr: ", stderr)
	out.Debugln("StdOut: ", stdout)
	return CmdResult{
		StdErr: stderr,
		StdOut: stdout,
		Err:    err,
	}
}

type ExitError

type ExitError = exec.ExitError

Jump to

Keyboard shortcuts

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