Documentation ¶
Index ¶
- func C(args ...string) []string
- func Supported() error
- type DefaultReporter
- type Reporter
- type Shell
- func (s *Shell) Err() error
- func (s *Shell) ForEach(args []string, f func(l string) bool) error
- func (s *Shell) Gox(args ...string) *Shell
- func (s *Shell) IsInvalid() bool
- func (s *Shell) O(args ...string) []byte
- func (s *Shell) OLog(args ...string) ([]byte, error)
- func (s *Shell) Pipe(out io.Writer, commands ...[]string) *Shell
- func (s *Shell) R(args ...string) (stdout, stderr io.Reader, err error)
- func (s *Shell) Refresh() *Shell
- func (s *Shell) Retry(num int, args ...string) *Shell
- func (s *Shell) X(args ...string) *Shell
- func (s *Shell) XLog(args ...string) *Shell
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DefaultReporter ¶
type DefaultReporter struct{}
DefaultReporter is the default implementation of Reporter.
func (DefaultReporter) Errorf ¶
func (r DefaultReporter) Errorf(format string, v ...interface{})
Errorf prints the occurred error.
func (DefaultReporter) Logf ¶
func (r DefaultReporter) Logf(format string, v ...interface{})
Errorf prints the information reported.
func (DefaultReporter) Stderr ¶
func (r DefaultReporter) Stderr() io.Writer
Stdout provides the writer to stderr.
func (DefaultReporter) Stdout ¶
func (r DefaultReporter) Stdout() io.Writer
Stdout provides the writer to stdout.
type Reporter ¶
type Reporter interface { // Errorf is called when Shell encounters unrecoverable error. Errorf(format string, v ...interface{}) // Logf is called to report some useful information (e.g. executing command) by Shell. Logf(format string, v ...interface{}) // Stdout is used as a stdout destination of executing commands. Stdout() io.Writer // Stdout is used as a stderr destination of executing commands. Stderr() io.Writer }
Reporter is used by Shell pkg to report logs and errors during commands execution.
type Shell ¶
Shell provides provides means to execute commands inside a container, in a shellscript-like experience.
func New ¶
When Shell encounters an unrecoverable error (e.g. failure of a command execution), this immediately calls Reporter.Errorf and don't execute the remaining (chained) commands. Err() method returns the last encountered error. Once Shell encounters an error, this is marked as "invalid" and doesn't accept any further command execution. For continuing further execution, call Refresh for aquiering a new instance of Shell.
Some useful information are also reported via Reporter.Logf during commands execution and command outputs to stdio are streamed into Reporter.Stdout and Reporter.Stderr.
If no Reporter is specified (i.e. nil is provided), DefaultReporter is used by default.
func (*Shell) ForEach ¶
ForEach executes a command. For each line of stdout, the callback function is called until it returns false. Stderr is streamed to Reporter. The encountered erros are returned instead of using Reporter.
func (*Shell) Gox ¶
Gox executes a command in an goroutine and doesn't wait for the command completion. Stdio is streamed to Reporter. When the command fails, different from X, the error is reported via Reporter.Logf and this Shell still *accepts* further command execution.
func (*Shell) IsInvalid ¶
IsInvalid returns true when this Shell is marked as "invalid". For continuing further command execution, call Refresh for aquiering a new instance of Shell.
func (*Shell) O ¶
O executes a command and return the stdout. Stderr is streamed to Reporter. When the command fails, the error is reported via Reporter.Errorf and this Shell is marked as "invalid" (i.e. doesn't accept further command execution).
func (*Shell) OLog ¶
OLog executes a command and return the stdout. Stdio is streamed to Reporter. When the command fails, different from O, the error is reported via Reporter.Logf and this Shell still *accepts* further command execution.
func (*Shell) Pipe ¶
Pipe executes passed commands sequentially and stdout of a command is piped into the next command's stdin. The stdout of the last command is streamed to the specified io.Writer. When a command fails, the error is reported via Reporter.Errorf and this Shell is marked as "invalid" (i.e. doesn't accept further command execution).
func (*Shell) Retry ¶
Retry executes a command repeatedly until it succeeds, up to num times. Stdio is streamed to Reporter. If all attemptions fail, the error is reported via Reporter.Errorf and this Shell is marked as "invalid" (i.e. doesn't accept further command execution).