Documentation
¶
Overview ¶
Package script aims to make it easy to write shell-type scripts in Go, for general system administration purposes: reading files, counting lines, matching strings, and so on.
Index ¶
- func CountLines(name string) (int, error)
- type Pipe
- func (p *Pipe) Close() error
- func (p *Pipe) CountLines() (int, error)
- func (p Pipe) Echo(s string) *Pipe
- func (p Pipe) Error() error
- func (p Pipe) Match(s string) *Pipe
- func (p Pipe) Reject(s string) *Pipe
- func (p *Pipe) SetError(err error)
- func (p *Pipe) String() (string, error)
- func (p *Pipe) WithCloser(r io.ReadCloser) *Pipe
- func (p *Pipe) WithError(err error) *Pipe
- func (p *Pipe) WithReader(r io.Reader) *Pipe
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CountLines ¶
CountLines counts lines in the specified file and returns the integer result, or an error, and closes the pipe after reading. If there is an error reading the pipe, the pipe's error status is also set.
Types ¶
type Pipe ¶
type Pipe struct { Reader io.ReadCloser // contains filtered or unexported fields }
Pipe represents a pipe object with an associated Reader.
func File ¶
File returns a *Pipe associated with the specified file. This is useful for starting pipelines. If there is an error opening the file, the pipe's error status will be set.
func (*Pipe) Close ¶
Close closes the pipe's associated reader. This is always safe to do, because pipes created from a non-closable source will have an `ioutil.NopCloser` to call.
func (*Pipe) CountLines ¶
CountLines counts lines from the pipe's reader, and returns the integer result, or an error. If there is an error reading the pipe, the pipe's error status is also set.
func (Pipe) Match ¶ added in v0.2.0
Match reads from the pipe, and returns a new pipe containing only lines which contain the specified string. If there is an error reading the pipe, the pipe's error status is also set.
func (Pipe) Reject ¶ added in v0.2.0
Reject reads from the pipe, and returns a new pipe containing only lines which do not contain the specified string. If there is an error reading the pipe, the pipe's error status is also set.
func (*Pipe) String ¶
String returns the contents of the Pipe as a string, or an error, and closes the pipe after reading. If there is an error reading, the pipe's error status is also set.
func (*Pipe) WithCloser ¶
func (p *Pipe) WithCloser(r io.ReadCloser) *Pipe
WithCloser takes an io.ReadCloser and associates the pipe with that source.