shell

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package shell implements spok's command running functionality

We use https://github.com/mvdan/sh so spok is entirely self contained and does not need an external shell at all to run.

This implementation is based on a similar one in https://github.com/go-task/task at internal/execext/exec.go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IntegratedRunner

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

IntegratedRunner implements Runner by using a 100% go implementation of a shell interpreter, this is the most cross-compatible version of a shell runner possible as it does not depend on any external shell.

func NewIntegratedRunner

func NewIntegratedRunner() IntegratedRunner

NewIntegratedRunner returns a shell runner with no external dependency.

func (IntegratedRunner) Run

func (i IntegratedRunner) Run(cmd string, stream iostream.IOStream, task string, env []string) (Result, error)

Run implements Runner for an IntegratedRunner, using a 100% go implementation of a shell interpreter.

Command stdout and stderr will be collected into the returned Result and optionally also printed to the writers in the IOStream, this allows output to be captured or discarded easily.

type Result

type Result struct {
	Cmd    string `json:"cmd"`    // The command that was run
	Stdout string `json:"stdout"` // The stdout of the command
	Stderr string `json:"stderr"` // The stderr of the command
	Status int    `json:"status"` // The exit status of the command
}

Result holds the result of running a shell command.

func (Result) Ok

func (r Result) Ok() bool

Ok returns whether the result was successful or not.

type Results

type Results []Result

Results is a collection of shell results.

func (Results) Ok

func (r Results) Ok() bool

Ok reports whether all results in the collection were ok.

type Runner

type Runner interface {
	// Run runs the shell command belonging to task with environment variables set.
	Run(cmd string, stream iostream.IOStream, task string, env []string) (Result, error)
}

Runner is an interface representing something capable of running shell commands and returning Results.

Jump to

Keyboard shortcuts

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