cmd

package
v0.0.0-...-5c471d0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exec

func Exec(path string, args ...string) error

Types

type Command

type Command struct {
	// contains filtered or unexported fields
}
Example
package main

import (
	"fmt"

	"github.com/lestrrat-go/scripting/cmd"
)

func main() {
	_, err := cmd.New("ls", "-l").
		CaptureStdout(true).
		Grep(`_test\.go$`).
		Do(nil)
	if err != nil {
		fmt.Printf("%s\n", err)
	}

}
Output:

func New

func New(path string, args ...string) *Command

New creates a new Command instance. `path` (i.e. the command to execute) is required. By default, `BailOnError` is true

func (*Command) BailOnError

func (c *Command) BailOnError(b bool) *Command

func (*Command) CaptureStderr

func (c *Command) CaptureStderr(b bool) *Command

func (*Command) CaptureStdout

func (c *Command) CaptureStdout(b bool) *Command

func (*Command) Do

func (c *Command) Do(ctx context.Context) (*Result, error)

Do executes the command, and applies other filters as necessary

func (*Command) Filter

func (c *Command) Filter(f filter.Filter) *Command

func (*Command) Grep

func (c *Command) Grep(pattern string) *Command

Grep adds a new filtering on the output of the command after it has been executed. `pattern` is treated as a regular expression. DO NOT forget to call one or both of `CaptureStderr` or `CaptureStdout`, otherwise there will be nothing to filter against.

func (*Command) PipeToFile

func (c *Command) PipeToFile(s string) *Command

func (*Command) Sed

func (c *Command) Sed(pattern, replace string) *Command

func (*Command) Spinner

func (c *Command) Spinner(b bool) *Command

func (*Command) Stdin

func (c *Command) Stdin(in io.Reader) *Command

Stdin sets a stdin to be piped to the command

type Result

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

func (*Result) JSON

func (r *Result) JSON(v interface{}) error

JSON assumes that your accumulated output is a JSON string, and attemps to decode it.

func (*Result) Output

func (r *Result) Output() *bytes.Buffer

func (*Result) OutputString

func (r *Result) OutputString() string

Jump to

Keyboard shortcuts

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