Crates.io | anticipate-cli |
lib.rs | anticipate-cli |
version | 0.6.0 |
source | src |
created_at | 2024-02-22 01:02:50.397517 |
updated_at | 2024-02-24 06:08:22.425819 |
description | Script runner with asciinema support |
homepage | |
repository | |
max_upload_size | |
id | 1148734 |
size | 74,145 |
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.
#!/bin/bash
#$ sendline ls -la
#$ sendcontrol ^C
#$ expect Documents
#$ regex [0-9]
#$ readline
#$ sleep 500
#$ send echo
#$ flush
#$ wait
#$ clear
#$ 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.
The core module is a fork of expectrl and the syntax is inspired by asciinema-automation.
MIT or Apache-2.0