Expect-Style Interactive Commands¶
Some commands prompt for input during execution — confirmation dialogs, setup
wizards, interactive installers. The interact feature lets you pre-define
responses to these prompts so the demo flows smoothly.
Basic usage¶
steps:
- text: "npm init"
interact:
- expect: "package name:"
send: "my-cool-app"
- expect: "version:"
send: "1.0.0"
- expect: "description:"
send: "A demo project"
- expect: "entry point:"
send: "index.js"
- expect: "Is this OK?"
send: "yes"
How it works¶
- The command is spawned with piped stdin and stdout
- Output is printed to the terminal as it arrives
- Each
expectpattern is checked against accumulated stdout - When a pattern matches, the
sendvalue (plus a newline) is written to stdin - The next
expectpattern becomes active - After all interactions complete, remaining output is printed
Interaction fields¶
| Field | Description |
|---|---|
expect |
String to match in the command's stdout |
send |
Text to send to stdin when matched (newline added) |
Examples¶
Confirming a destructive action¶
Git interactive rebase (simplified)¶
Multi-step installer¶
- text: "curl -sSL https://install.example.com | sh"
interact:
- expect: "Install location"
send: "/usr/local"
- expect: "Add to PATH?"
send: "y"
- expect: "Enable telemetry?"
send: "n"
Limitations¶
- The
expectmatch is a simple string contains check, not regex - Interactions are processed in order — you cannot skip or reorder them
- Each interaction has a 30-second timeout; if the expected pattern doesn't appear, the interaction is abandoned
- Programs that disable echo or use raw terminal mode (like password prompts) may not work because output is piped rather than using a PTY
- stderr is inherited directly (not piped), so patterns must appear on stdout
Tips¶
- Test your interact sequences with
--dry-runfirst to see the flow - Keep
sendvalues short and unambiguous - If a program requires an empty response (just pressing Enter), use
send: "" - For commands that only need a
y/nconfirmation, this is much cleaner than pipingecho y |into the command