execopt

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: GPL-3.0, LGPL-3.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func DiesWithParent(ctx context.Context) bool

DiesWithParent reports whether ctx is one WithDiesWithParent returned.

func Env

func Env(ctx context.Context) []string

Env returns the environment WithEnv put in ctx, or nil.

func InProcessGroup

func InProcessGroup(ctx context.Context) bool

InProcessGroup reports whether ctx is one WithProcessGroup returned.

func LineParser

func LineParser(ctx context.Context) func(progress.Stream, string)

LineParser returns the function WithLineParser put in ctx, or nil.

func OrphanSafe

func OrphanSafe(ctx context.Context) bool

OrphanSafe reports whether ctx is one WithOrphanSafe returned.

func OutputLimit

func OutputLimit(ctx context.Context) int

OutputLimit returns the limit of WithOutputLimit, zero without one.

func Started

func Started(ctx context.Context) func(pid int)

Started returns the function WithStarted put in ctx, or nil.

func StderrMerged

func StderrMerged(ctx context.Context) bool

StderrMerged reports whether ctx is one WithStderrMerged returned.

func StdoutIsData

func StdoutIsData(ctx context.Context) bool

StdoutIsData reports whether ctx is one WithStdoutAsData returned.

func StopGrace

func StopGrace(ctx context.Context) time.Duration

StopGrace returns the grace of WithStopGrace, zero without one.

func Terminal

func Terminal(ctx context.Context) bool

Terminal reports whether WithTerminal put a terminal in ctx.

func TerminalOpened

func TerminalOpened(ctx context.Context) func()

TerminalOpened returns the function WithTerminalOpened put in ctx, or nil.

func WithDiesWithParent

func WithDiesWithParent(ctx context.Context) context.Context

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

func WithEnv(ctx context.Context, env []string) context.Context

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

func WithLineParser(ctx context.Context, parse func(progress.Stream, string)) context.Context

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

func WithOrphanSafe(ctx context.Context) context.Context

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

func WithOutputLimit(ctx context.Context, n int) context.Context

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

func WithProcessGroup(ctx context.Context) context.Context

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

func WithStarted(ctx context.Context, started func(pid int)) context.Context

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

func WithStderrMerged(ctx context.Context) context.Context

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

func WithStdoutAsData(ctx context.Context) context.Context

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

func WithStopGrace(ctx context.Context, grace time.Duration) context.Context

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

func WithTerminal(ctx context.Context) context.Context

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

func WithTerminalOpened(ctx context.Context, opened func()) context.Context

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.

func (*TerminalLines) Write

func (t *TerminalLines) Write(p []byte) (int, error)

Write cuts p into lines, and writes those that ended to w at once. It returns len(p) unless w fails.

Jump to

Keyboard shortcuts

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