Skip to main content

Automate the Codiac CLI - Scripting, Piping, and Output Formats

The Codiac CLI is built for both humans and scripts. Interactive prompts guide you when you're exploring; clean output modes let you pipe and automate without surprises.

Output formats

Commands that return data support the --output (-o) flag:

FormatUse it when...
treeYou're reading the result in a terminal (default)
jsonYou're piping to jq, saving to a file, or feeding another tool
yamlYou want the result as a YAML document
csv / tsvYou're importing into a spreadsheet or awk
# Human-readable in the terminal
cod config view -a myapi -c dev

# Machine-readable for a script
cod config view -a myapi -c dev -o json

# Filtered with jq
cod asset list -o json | jq '.[].name'
tip

Use -q (JMESPath query) to filter or reshape the output directly in the CLI, without needing a separate jq step. See Filtering output with --query below.


Saving output to a file

Redirect stdout with > as you normally would. Status messages, prompts, and spinner output all stay on your terminal — only the data payload goes into the file.

cod config view -a myapi -c dev -o json > myconfig.json

If you haven't provided all the required flags, the CLI will prompt you interactively in your terminal while still writing only the final data to the file. Once you've answered the prompts, the file gets exactly what you asked for and nothing else.

# Missing --cabinet: the CLI will prompt you to pick one,
# then write the result to myconfig.json
cod config view -a myapi -o json > myconfig.json

Non-interactive (scripted) mode

Add --silent to skip all prompts and fail immediately if a required flag is missing. This is the right mode for CI/CD pipelines where there's no keyboard.

cod config view -a myapi -c dev -o json --silent > myconfig.json

In silent mode, the CLI throws a clear error (on stderr, so it shows up in your build logs) if you've left out a required argument:

Error: Cabinet name (--cabinet or -c) is required in silent mode.

Piping output into another command

stdout is clean data, so piping works as you'd expect:

# View config as JSON and pipe it to another tool
cod config view -a myapi -c dev -o json | jq '.database.connectionString'

# List assets and pass names downstream
cod asset list -o json | jq -r '.[].name' | xargs -I{} echo "Asset: {}"

Piping input into the CLI

Some commands accept piped-in data as input — for example, cod config add can read a full config document from stdin:

cat myconfig.json | cod config add -a myapi -c dev

When the CLI detects piped stdin, it automatically engages silent mode. All required values must be provided as flags; the CLI will not prompt.


Filtering output with --query

Use -q with a JMESPath expression to filter or reshape the result before it reaches your terminal or pipe. When -q is used without -o, the CLI defaults to JSON output automatically.

# Names only
cod asset list -q '[].name'

# Custom projection
cod asset list -q '[].{ name: name, cabinet: cabinetName }'

# Filter by value
cod asset list -q "[?cabinetName == 'dev']"

# Sort by a field
cod asset list -q "[].{ name: name, cab: cabinetName } | sort_by(@, &cab)"

# Export as YAML
cod asset list -o yaml

Preview the non-interactive command

Not sure which flags to use in a script? Run interactively with --echo to have the CLI guide you through the prompts and then print the equivalent --silent command at the end:

cod config view --echo

Or use --to-script to get the command string without actually executing it:

cod config view --to-script

You can copy the printed command directly into a script or CI/CD step.


How it works under the hood

The CLI routes every output to the correct stream so shell redirection behaves predictably:

  • stderr — prompts, confirmations, status messages, spinner, log output. Always visible on your terminal, even when stdout is redirected. Never ends up in your file.
  • stdout — only the data payload (JSON, YAML, etc.). This is what > and | capture.

This is the same model used by az, aws, gcloud, and kubectl. If you've automated any of those CLIs before, the Codiac CLI works exactly the same way.