Use in Scripts¶
How to consume tlm-cli output in shell scripts, CI pipelines, and Docker containers.
In plain mode the CLI emits newline-delimited JSON to stdout and plain-text warnings or errors to stderr. This makes it
safe to pipe into jq or redirect to a file without Rich formatting or interactive prompts interfering.
Activate plain mode¶
Three equivalent ways to activate plain mode:
Flag¶
Environment variable¶
Automatic — pipe or redirect stdout¶
# No flag needed: piping stdout triggers plain mode automatically
tlm-cli pms devices list | jq
tlm-cli pms models list > models.json
Output shape¶
List commands emit a JSON array — one object per row:
tlm-cli --plain pms models list
# [{"Name":"gateway-v2","Description":"Main gateway","Tags":"","Customers":"ACME"},...]
Show and detail commands emit a JSON object:
tlm-cli --plain pms models show "gateway-v2"
# {"Name":"gateway-v2","Description":"Main gateway","Tags":"","Customers":"ACME"}
Parse output with jq¶
Extract a single field from every row:
Filter rows by field value:
Get a comma-separated list of serial numbers:
Extract a field from a detail view:
Use in a shell script¶
#!/usr/bin/env bash
set -euo pipefail
export TLM_CLI_PLAIN=1
# Fetch all model names
models=$(tlm-cli pms models list | jq -r '.[].Name')
for model in $models; do
echo "Processing $model..."
tlm-cli pms models show "$model" | jq -r '.Description'
done
Use in Docker or CI¶
Set TLM_CLI_PLAIN=1 in your environment or Dockerfile:
In a CI pipeline (e.g. GitLab CI):
Errors and warnings¶
Errors are written to stderr with an error: prefix and exit code 1:
# Show only errors (suppress JSON output)
tlm-cli pms models show "nonexistent" 2>&1 1>/dev/null
# error: model not found: nonexistent
Warnings are written to stderr with a warning: prefix and do not affect the exit code:
Redirect stderr separately to capture both streams independently: