Help us shape the future of Go! Take the 2026 Go Developer Survey

mole

package module
v0.0.0-...-d8837ee Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2018 License: MIT Imports: 4 Imported by: 0

README

mole

Build Status

mole is a wrapper of exec.Cmd suite for executing piped commands.

Usage

import "github.com/kagemiku/mole"

mole := mole.NewMole()
  • Mole.Output()
mole := mole.NewMole()
mole.Add("ls", "-la")
mole.Add("head", "-5")
mole.Add("wc", "-l")
mole.Add("tr", "-d", " ")

out, err := mole.Output()
if err != nil {
	log.Fatal(err)
}
fmt.Println(string(out))
  • Mole.Run()
mole := mole.NewMole()
mole.Add("wc", "-c")

var buf bytes.Buffer
buf.WriteString("hoge")
mole.Stdin = &buf
mole.Stdout = os.Stdout
if err := mole.Run(); err != nil {
	log.Fatal(err)
}

License

MIT License

Author

kagemiku

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mole

type Mole struct {
	Stdin  io.Reader
	Stdout io.Writer
	// contains filtered or unexported fields
}

Mole is a structure for running piped command

func NewMole

func NewMole() *Mole

NewMole generates a new Mole instance

func (*Mole) Add

func (m *Mole) Add(name string, arg ...string)

Add adds command to command list

func (*Mole) Output

func (m *Mole) Output() ([]byte, error)

Output runs command list, and returns stdout content as []byte

func (*Mole) Run

func (m *Mole) Run() error

Run runs command list

If you want to get the stdout content, please use Output instead, or pass some io.Writer instance to the Mole.Stdout

Jump to

Keyboard shortcuts

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