Script based automation like expect(1)
with support for asciinema.
Perfect for demos and testing command line interfaces.
cargo install anticipate-cli
Create a directory, initialize a server config, print the config file, start the server and then send SIGTERM to shut it down.
mkdir -p target/server/accounts
#$ readline
server init target/config.toml --path server/accounts
#$ readline
cat target/config.toml
#$ expect path = "server/accounts"
server start target/config.toml
#$ sendcontrol ^C
See the examples
and fixtures
folders for more examples.
To execute scripts use the run
command:
anticipate \
run \
--parallel \
--log \
tests/examples/*.sh
To record using asciinema writing a .cast
file for each input file into the target
directory overwriting any existing files:
anticipate \
record \
--parallel \
--overwrite \
--log \
target \
tests/examples/*.sh
See the progam help for more options.
- pragma -
#!/bin/bash
- sendline -
#$ sendline ls -la
- sendcontrol -
#$ sendcontrol ^C
- expect -
#$ expect Documents
- regex -
#$ regex [0-9]
- readline -
#$ readline
- sleep -
#$ sleep 500
- send -
#$ send echo
- flush -
#$ flush
- wait -
#$ wait
- clear -
#$ clear
- include -
#$ include ../shared.sh
Environment variables are interpolated for commands sent to the pseudo terminal which makes it easier to share values across scripts.
export NAME=foo
anticipate rec -o target tests/examples/interpolate.sh
asciinema play target/interpolate.cast
Use a pragma as the first instruction to set the command to execute:
#!/bin/bash
If a relative path is given it is resolved relative to the script:
#!../programs/script.sh
Raw text is sent as a line to the pseudo-terminal:
ls -la
Or you can use the sendline command explicitly:
#$ sendline ls -la
To send a control character, for example Ctrl+C:
#$ sendcontrol ^C
Expect waits for a string to appear in the program output:
#$ expect Documents
To wait for a pattern to appear in the program output use regex
:
#$ regex [0-9]
Read a line of program output:
#$ readline
Wait for a number of milliseconds:
#$ sleep 500
Send text to the program without flushing the stream:
#$ send echo
Flush the buffer being sent to the pseudo-terminal:
#$ flush
Wait for the prompt to appear:
#$ wait
Clear the screen and reset the cursor position:
#$ clear
Include instructions from a script file:
#$ include ../shared.sh
Paths are resolved relative to the parent directory of the script file.
- Autocast if you prefer a YAML syntax
- Asciinema Integrations for other asciinema tools
The core module is a fork of expectrl and the syntax is inspired by asciinema-automation.
MIT or Apache-2.0