executil

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package executil holds tiny helpers shared by the exec runners.

Index

Constants

This section is empty.

Variables

View Source
var IsStdinTerminal = func() bool {
	fi, err := os.Stdin.Stat()
	if err != nil {
		return false
	}
	return fi.Mode()&os.ModeCharDevice != 0
}

IsStdinTerminal reports whether stdin is connected to a terminal. dotdrift uses it to decide whether a generated mise hook task may opt into interactive mode (interactive = true): when stdin is a TTY, an interactive command inside a hook (e.g. sudo) gets a controlling terminal so it can disable echo, instead of reading the password with echo on. Stdlib-only char-device check (golang.org/x/term is not vendored). A variable so tests and callers can substitute it.

View Source
var IsTerminal = func(w io.Writer) bool {
	f, ok := w.(*os.File)
	if !ok || f == nil {
		return false
	}
	fi, err := f.Stat()
	if err != nil {
		return false
	}
	return fi.Mode()&os.ModeCharDevice != 0
}

IsTerminal reports whether w is a terminal (char device), generalizing IsStdinTerminal to any writer. A non-*os.File (capture buffer) or a regular file never qualifies. A variable so tests and callers can substitute it.

View Source
var NoColor bool

NoColor disables ANSI color output in dotdrift's own rendering when true. Set by the --no-color flag or the NO_COLOR env var (no-color.org standard).

Functions

func ColorEnabled added in v0.16.0

func ColorEnabled(w io.Writer) bool

ColorEnabled reports whether color should be applied for w: it is a terminal and NoColor has not been set.

func EchoCommand

func EchoCommand(w io.Writer, argv []string)

EchoCommand writes the set -x-style echo line "+ <argv>\n" to w.

func OrStderr added in v0.21.0

func OrStderr(w io.Writer) io.Writer

OrStderr returns w if non-nil, else os.Stderr.

func OrStdout added in v0.21.0

func OrStdout(w io.Writer) io.Writer

OrStdout returns w if non-nil, else os.Stdout. Replaces the repeated `out := c.Out; if out == nil { out = os.Stdout }` pattern.

func ShellJoin

func ShellJoin(argv []string) string

ShellJoin renders argv as a shell-style command line: elements are joined with single spaces; any element containing whitespace or a single quote is single-quoted (each ' escaped as '\”), bash set -x style. Simple elements pass through unquoted. Empty argv joins to the empty string.

func StreamLive added in v0.12.0

func StreamLive(verbose bool, out, err io.Writer) bool

StreamLive reports whether a child's stdout/stderr should stream live to out/err instead of being captured. Streaming connects the child's fds directly to out/err, so when they are terminals the child keeps its own color output — and its output stays off error/log lines instead of being jammed into an error value. It streams under verbose (the set -x trace) or whenever both destinations are terminals (an interactive apply); a non-verbose, piped run still captures so a failure carries self-contained diagnostics.

Types

type LockedWriter added in v0.8.0

type LockedWriter struct {
	W io.Writer
	// contains filtered or unexported fields
}

LockedWriter serializes concurrent writes to W. os/exec spawns one copy goroutine per stream when Stdout and Stderr are different writers, so two MultiWriters capturing into one bytes.Buffer race (and silently lose writes) without it.

func (*LockedWriter) Write added in v0.8.0

func (l *LockedWriter) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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