Skip to main content

Module exec

Module exec 

Source
Expand description

gwm exec (issue #313): run a command across worktrees and roll up the results.

The CLI handler in cli.rs resolves which worktrees to target and prints the output; everything testable lives here: the spawn primitive (exec_in_dir), the aggregate exit code (rollup_exit_code), and the per-worktree line formatter (format_outcome). Execution is sequential — deterministic, readable output for the MVP; parallel fan-out is a deliberate follow-up.

Structs§

ExecOutcome
A worktree’s display name paired with its command outcome.

Enums§

ExecStatus
Outcome of running the command inside one worktree.

Functions§

exec_capture_in_dir
Like exec_in_dir, but CAPTURE stdout+stderr (stdout then stderr) instead of inheriting the parent’s stdio. Used by run_in_dirs_parallel so concurrent worktrees don’t interleave their output — each block is printed whole, in worktree order, after the fan-out completes.
exec_in_dir
Run program args… with the working directory set to dir.
format_outcome
Render one rollup line for a worktree using the repo’s ✓ / ✗ sigils, e.g. ✓ feat-1 or ✗ fix-2 (exit 2).
resolve_exec_command
Resolve the argv gwm exec should run, from exactly one source: an inline -- <cmd> or a --profile <name> (issue #324).
resolve_jobs
Resolve the effective parallelism for gwm exec (issue #324): the --jobs flag wins, then the selected profile’s jobs, then the global [exec] jobs, else 1. A resolved 0 (or absent) means sequential. Always returns a worker count >= 1.
resolve_program
Resolve program for execution inside dir.
rollup_exit_code
Aggregate exit code for the whole fan-out: 0 only when every worktree succeeded, else 1. Mirrors the repo’s doctor/CI convention of a single non-zero “something failed” code rather than trying to reconcile multiple distinct child codes into one.
run_in_dirs_parallel
Run program args… in each (name, dir) of items with up to jobs concurrent workers, capturing each one’s output. Returns one (ExecOutcome, captured_output) per item in input order (not completion order), so the caller prints deterministic per-worktree blocks regardless of which finished first. jobs is clamped to [1, items.len()].
validate_exec_profile_command
Validate a [exec.profiles.<name>] entry’s command: it must be a non-empty argv array. Surfaced for the config validation path so gwm config validate / gwm doctor reject what gwm exec --profile would (issue #324 review).

Type Aliases§

CapturedRun
One parallel worktree run: its ExecOutcome plus the captured stdout+stderr bytes printed as a block by the caller.