executor

package
v0.0.0-...-9994f1b Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Copyright 2023 The Chromium Authors Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExecCommander

type ExecCommander struct{}

ExecCommander is a wrapper uses to execute a command.

func (*ExecCommander) CombinedOutput

func (e *ExecCommander) CombinedOutput(cmd *exec.Cmd) ([]byte, error)

func (*ExecCommander) Output

func (e *ExecCommander) Output(cmd *exec.Cmd) ([]byte, error)

func (*ExecCommander) Start

func (e *ExecCommander) Start(cmd *exec.Cmd) error

func (*ExecCommander) Wait

func (e *ExecCommander) Wait(cmd *exec.Cmd) error

type FakeCommander

type FakeCommander struct {
	CmdOutput string
	Err       error
	FakeFn    func(*exec.Cmd) ([]byte, error)
}

FakeCommander is used to fake a result when user write some test cases.

func (*FakeCommander) CombinedOutput

func (f *FakeCommander) CombinedOutput(in *exec.Cmd) ([]byte, error)

func (*FakeCommander) Output

func (f *FakeCommander) Output(in *exec.Cmd) ([]byte, error)

func (*FakeCommander) Start

func (f *FakeCommander) Start(in *exec.Cmd) error

func (*FakeCommander) Wait

func (f *FakeCommander) Wait(c *exec.Cmd) error

type IExecCommander

type IExecCommander interface {
	// CombinedOutput runs the command and returns its combined standard
	// output and standard error. It wrpas the error inside `fmt.Errorf`.
	//
	// if we want to parse *ExitError, we can use `errors.Unwrap` to achieve.
	CombinedOutput(*exec.Cmd) ([]byte, error)

	// Output runs the command and returns its standard output.
	// Any returned error will usually be of type *ExitError.
	// If c.Stderr was nil, Output populates ExitError.Stderr.
	Output(*exec.Cmd) ([]byte, error)

	// Start starts the specified command but does not wait for it to complete.
	//
	// If Start returns successfully, the c.Process field will be set.
	//
	// After a successful call to Start the Wait method must be called in
	Start(*exec.Cmd) error

	// Wait waits for the command to exit and waits for any copying to
	// stdin or copying from stdout or stderr to complete.
	//
	// The command must have been started by Start.
	//
	// The returned error is nil if the command runs, has no problems
	// copying stdin, stdout, and stderr, and exits with a zero exit
	// status.
	//
	// If the command fails to run or doesn't complete successfully, the
	// error is of type *ExitError. Other error types may be
	// returned for I/O problems.
	//
	// If any of c.Stdin, c.Stdout or c.Stderr are not an *os.File, Wait also waits
	// for the respective I/O loop copying to or from the process to complete.
	//
	Wait(*exec.Cmd) error
}

IExecCommander is a interface to define which functions we can use in a commander.

Jump to

Keyboard shortcuts

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