Documentation ¶
Index ¶
- func Exec(path string, args ...string) error
- type Command
- func (c *Command) BailOnError(b bool) *Command
- func (c *Command) CaptureStderr(b bool) *Command
- func (c *Command) CaptureStdout(b bool) *Command
- func (c *Command) Do(ctx context.Context) (*Result, error)
- func (c *Command) Filter(f filter.Filter) *Command
- func (c *Command) Grep(pattern string) *Command
- func (c *Command) PipeToFile(s string) *Command
- func (c *Command) Sed(pattern, replace string) *Command
- func (c *Command) Spinner(b bool) *Command
- func (c *Command) Stdin(in io.Reader) *Command
- type Result
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
New creates a new Command instance. `path` (i.e. the command to execute) is required. By default, `BailOnError` is true
func (*Command) BailOnError ¶
func (*Command) CaptureStderr ¶
func (*Command) CaptureStdout ¶
func (*Command) Grep ¶
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 ¶
Click to show internal directories.
Click to hide internal directories.