Reference
This reference provides a overview of all CLI/test syntax elements organized by category.
Command Execution
Command | Description | Location |
---|---|---|
$ <command> … | Execute a shell command and match its output | Basic Usage |
%EXIT <n> | Expect command to exit with specific code n | Basic Usage |
%EXIT fail | Expect command to exit with any non-zero code | Basic Usage |
%EXIT any | Accept any exit code (including timeouts) | Basic Usage |
%EXIT timeout | Expect command to timeout | Advanced Features |
%TIMEOUT <duration> | Set timeout for a command (e.g., 100ms, 5s) | Advanced Features |
%SET <variable> | Capture full command output into a variable | Environment |
%SET <variable> <pattern> | Capture grok captures into a variable | Environment |
%EXPECT <alias> <value> | Expect a grok capture to match a value | Grok Patterns |
%EXPECT_FAILURE | Expect pattern matching to fail | Advanced Features |
Variables and Quoting
clitest uses shell-style variable references and quoting to delimit strings in commands and control structures.
Quote Type | Behavior | Location |
---|---|---|
'text' | Single quotes - literal value, no expansion | Control Structures |
"text" | Double quotes - literal value with variable expansion | Control Structures |
\char | Backslash escape - preserve literal meaning | Control Structures |
$VAR | Basic variable reference | Environment |
${VAR} | Explicit variable reference | Environment |
$PWD | Special variable for working directory | Environment |
Control Structures
Structure | Description | Location |
---|---|---|
# <comment> | Ignore this line during test execution | Control Structures |
include "path/to/script.cli"; | Include a script into the current script | Control Structures |
if condition { … } | Conditionally execute commands or patterns | Control Structures |
for <var> in <…> { … } | Iterate over a list of values | Control Structures |
background { … } | Run commands in background (auto-killed on exit) | Control Structures |
defer { … } | Execute cleanup commands after block ends (LIFO order) | Control Structures |
retry { … } | Retry commands until success or timeout | Control Structures |
exit script; | Exit script early with success status | Control Structures |
set <var> <value>; | Set environment variable directly | Environment |
cd <directory>; | Change working directory | Environment |
using tempdir; | Create and use temporary directory (auto-deleted) | Environment |
using new dir <name>; | Create new directory for testing (auto-deleted) | Environment |
using dir <path>; | Use existing directory (not deleted) | Environment |
pattern <NAME> <regex>; | Define custom grok pattern | Grok Patterns |
Patterns
Pattern | Description | Location |
---|---|---|
! <text> | Auto-escaped pattern (literal text matching + grok patterns) | Pattern Matching |
? <pattern> | Raw pattern (regex-style, requires escaping + grok patterns) | Pattern Matching |
!!! | Multi-line auto-escaped pattern block | Pattern Matching |
??? | Multi-line raw pattern block | Pattern Matching |
""" | Multi-line literal block | Pattern Matching |
* | Any pattern (matches any number of lines lazily) | Pattern Matching |
%{PATTERN_NAME} | Standard grok pattern | Grok Patterns |
%{PATTERN_NAME=(regex)} | Custom grok pattern with regex | Grok Patterns |
%{PATTERN_NAME:field_name} | Named grok pattern with output field | Grok Patterns |
%{PATTERN_NAME:field_name=(regex)} | Custom named grok pattern | Grok Patterns |
repeat { … } | Match pattern multiple times | Pattern Matching |
choice { … } | Match any one of specified patterns | Pattern Matching |
unordered { … } | Match patterns in any order | Pattern Matching |
sequence { … } | Match patterns in strict order | Pattern Matching |
optional { … } | Make pattern optional (zero or one match) | Pattern Matching |
if <condition> { … } | Conditionally require patterns | Pattern Matching |
not { … } | Negative lookahead pattern | Pattern Matching |
ignore { … } | Skip/ignore certain output patterns | Pattern Matching |
reject { … } | Ensure patterns don't appear in output | Pattern Matching |
Common Grok Patterns
This is a subset of the grok patterns supported by clitest. See the full list of
supported patterns at https://docs.rs/grok/latest/grok/patterns/index.html,
including the full base patterns in the grok
module:
https://docs.rs/grok/latest/grok/patterns/grok/index.html.
Pattern | Description | Example |
---|---|---|
%{DATA} | Matches any text (lazy) | Hello, %{DATA} |
%{GREEDYDATA} | Matches any text (greedy) | Hello, %{GREEDYDATA} |
%{WORD} | Matches word characters | [%{WORD}] |
%{NUMBER} | Matches numeric values | Count: %{NUMBER} |