Documentation
¶
Overview ¶
Package execopt holds the options that sind's packages give cmdexec.OSExecutor in the context of a call. They are internal: an Executor of a library caller may ignore them (see cmdexec.Executor).
Index ¶
- Constants
- func DiesWithParent(ctx context.Context) bool
- func Env(ctx context.Context) []string
- func InProcessGroup(ctx context.Context) bool
- func LineParser(ctx context.Context) func(progress.Stream, string)
- func OrphanSafe(ctx context.Context) bool
- func OutputLimit(ctx context.Context) int
- func Started(ctx context.Context) func(pid int)
- func StderrMerged(ctx context.Context) bool
- func StdoutIsData(ctx context.Context) bool
- func StopGrace(ctx context.Context) time.Duration
- func Terminal(ctx context.Context) bool
- func TerminalOpened(ctx context.Context) func()
- func WithDiesWithParent(ctx context.Context) context.Context
- func WithEnv(ctx context.Context, env []string) context.Context
- func WithLineParser(ctx context.Context, parse func(progress.Stream, string)) context.Context
- func WithOrphanSafe(ctx context.Context) context.Context
- func WithOutputLimit(ctx context.Context, n int) context.Context
- func WithProcessGroup(ctx context.Context) context.Context
- func WithStarted(ctx context.Context, started func(pid int)) context.Context
- func WithStderrMerged(ctx context.Context) context.Context
- func WithStdoutAsData(ctx context.Context) context.Context
- func WithStopGrace(ctx context.Context, grace time.Duration) context.Context
- func WithTerminal(ctx context.Context) context.Context
- func WithTerminalOpened(ctx context.Context, opened func()) context.Context
- type TerminalLines
Constants ¶
const TerminalWidth = 100
TerminalWidth is the width of the pseudo-terminal of WithTerminal, in columns: wide enough for docker pull to write its byte counts and the time left, too narrow for it to draw a bar as well.
Variables ¶
This section is empty.
Functions ¶
func DiesWithParent ¶
DiesWithParent reports whether ctx is one WithDiesWithParent returned.
func InProcessGroup ¶
InProcessGroup reports whether ctx is one WithProcessGroup returned.
func LineParser ¶
LineParser returns the function WithLineParser put in ctx, or nil.
func OrphanSafe ¶
OrphanSafe reports whether ctx is one WithOrphanSafe returned.
func OutputLimit ¶
OutputLimit returns the limit of WithOutputLimit, zero without one.
func StderrMerged ¶
StderrMerged reports whether ctx is one WithStderrMerged returned.
func StdoutIsData ¶
StdoutIsData reports whether ctx is one WithStdoutAsData returned.
func TerminalOpened ¶
TerminalOpened returns the function WithTerminalOpened put in ctx, or nil.
func WithDiesWithParent ¶
WithDiesWithParent returns ctx for a stream that must not outlive this process, such as docker events: it reads no standard input, and learns that nobody reads its output only when it writes the next event, which may never come. On Linux, cmdexec.Start has the kernel kill such a command when this process dies, however it dies. On other systems the command stays, as it does without this option.
func WithEnv ¶
WithEnv returns ctx for a command that OSExecutor runs with env, in the form of os.Environ, as its whole environment instead of the process's own. An empty env is the process's own, as without WithEnv.
func WithLineParser ¶
WithLineParser returns ctx for a command whose output a caller follows line by line as it is written, such as the status lines of docker pull that tell how far an image has got: OSExecutor hands each line of its standard error, and of its standard output unless that is data (WithStdoutAsData), to parse as it ends, without its line break, with the stream it came from. parse is called from the goroutine that copies the stream, so the calls for the two streams may run at the same time, and must not block; a line that has not ended when the output does is none it is given. The output is captured as without a parser.
func WithOrphanSafe ¶
WithOrphanSafe returns ctx for a command that must not die with this process, such as a sind that sind ui runs: once nobody reads a pipe, the next write to it ends the writer with SIGPIPE, which can be before its rollback. OSExecutor gives such a command no pipe: its standard output goes to the null device, its standard error to an unlinked temporary file, which Run returns when the command ends. On Linux the command also gets SIGINT when this process dies, as Ctrl-C sends, so that it stops and rolls back.
func WithOutputLimit ¶
WithOutputLimit returns ctx for a command whose standard output and standard error OSExecutor.Run keeps to about n bytes each, such as one whose output a server returns: the first and the last n/2 bytes, with a line between them that says how many bytes it left out. Without it, Run keeps all of it.
func WithProcessGroup ¶
WithProcessGroup returns ctx for a command that OSExecutor runs in a process group of its own and, when ctx ends, kills with every process it started that is still in that group, such as a docker CLI. Killing the command alone would leave them running, holding its output open, so the command would be reported done only when they end.
func WithStarted ¶
WithStarted returns ctx for a command whose process ID its caller needs while it runs, such as to signal it: OSExecutor calls started with the ID once the command has started, from the goroutine that runs it, before it waits for the command to end. It is not called for a command that cannot be started.
func WithStderrMerged ¶
WithStderrMerged returns ctx for a long-lived command (Start) whose standard error is read with its standard output, as one stream: docker logs, for one, writes what the container wrote to its standard error to its own.
func WithStdoutAsData ¶
WithStdoutAsData returns ctx for a command whose standard output is data its caller reads, such as an ID, a name or JSON, rather than lines that say what the command is doing: under a progress span that shows lines, OSExecutor then shows the lines of its standard error alone.
func WithStopGrace ¶
WithStopGrace returns ctx for a command run WithProcessGroup that stops on SIGTERM itself, with what it started, such as sind, which rolls back what it began. When ctx ends, OSExecutor sends SIGTERM to the command alone, and kills its process group only once grace has passed. Without it, the end of ctx kills the group at once.
func WithTerminal ¶
WithTerminal returns ctx for a command that writes more to a terminal than to a pipe, such as docker pull, which writes the bytes each layer has downloaded only to a terminal: OSExecutor gives its standard output a pseudo-terminal of TerminalWidth columns, and turns what the command writes there into plain lines (NewTerminalLines) before it captures them or hands them to a line parser. Where it cannot open one, the command writes to a pipe, as without WithTerminal. Standard error stays a pipe.
func WithTerminalOpened ¶
WithTerminalOpened returns ctx for a command run WithTerminal whose caller needs to know that it got the terminal, as a parser of what docker pull writes does, which reads the bytes only where docker writes them: OSExecutor calls opened once it has opened the terminal, before the command starts, and not at all where it writes to a pipe instead.
Types ¶
type TerminalLines ¶
type TerminalLines struct {
// contains filtered or unexported fields
}
TerminalLines writes what a command wrote to a terminal as plain lines, each ended by "\n", without the escape sequences that move the cursor or erase. A carriage return, a line feed and a move of the cursor up or down end a line, as a program that redraws lines in place, such as the progress of docker pull, writes one line before each of them; a line of blanks only is left out, and the blanks around a line are cut. Other control characters are left out. It is not safe for concurrent use.
func NewTerminalLines ¶
func NewTerminalLines(w io.Writer) *TerminalLines
NewTerminalLines returns a TerminalLines that writes its lines to w.
func (*TerminalLines) Flush ¶
func (t *TerminalLines) Flush() error
Flush writes the line that has not ended, if any.