Skip to content

Scripting And JSON Output

Use JSON output whenever another tool needs to parse the result:

Terminal window
gaard whoami -o json
gaard token list -o json
gaard tenant list -o json

Table output is the default for interactive terminal use.

You do not need to switch the global config just to run one command against a different environment.

Run a command against a specific context:

Terminal window
gaard --context staging whoami -o json

Run a command against a specific tenant:

Terminal window
gaard --context prod --tenant acme_prod token list -o json

Good automation patterns:

  • Prefer -o json
  • Pass --context and --tenant explicitly when the environment matters
  • Use --no-color when logs may be parsed or stored
  • Store custom config files with GAARD_CONFIG when running isolated jobs

Example:

Terminal window
GAARD_CONFIG=/tmp/gaard-ci.yaml \
gaard --context staging --tenant acme_prod whoami -o json --no-color

Use gaard token create to mint a personal access token for a bot or script:

Terminal window
gaard token create --name ci-bot --expires 720h

The command prints the raw token once. Store it immediately in your secret manager or CI variable store.

Human-friendly versus machine-friendly output

Section titled “Human-friendly versus machine-friendly output”

Choose output based on the caller:

  • table for humans in a terminal
  • json for scripts, CI, and AI agents

If you are building higher-level automation, prefer wrapping gaard commands rather than scraping table output.