Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

wcl query

Execute a query expression against a WCL document.

Usage

wcl query <file> <query> [options]
wcl query --recursive <dir> <query> [options]

Options

FlagDescription
--format <fmt>Output format: text, json, csv, or wcl (default: text)
--countPrint the number of matching results instead of the results themselves
--recursiveSearch recursively across all .wcl files in a directory

Description

wcl query evaluates a query pipeline against the resolved document and prints matching results. The query syntax is the same as the inline query(...) expression in WCL source.

A query pipeline is a selector followed by zero or more filters separated by |.

Selectors

SyntaxSelects
serviceAll blocks of type service
service#svc-apiBlock with type service and ID svc-api
..serviceAll service blocks at any depth
*All top-level items
.The root document

Filters

SyntaxMeaning
.portHas attribute port
.port == 8080Attribute port equals 8080
.name =~ "api.*"Attribute name matches regex
has(.port)Has attribute port
has(@deprecated)Has decorator @deprecated
@tag.env == "prod"Decorator @tag has named arg env equal to "prod"

Examples

Select all services:

wcl query config.wcl 'service'

Select a specific block by ID:

wcl query config.wcl 'service#svc-api'

Filter by attribute value:

wcl query config.wcl 'service | .port == 8080'

Filter by regex match:

wcl query config.wcl 'service | .name =~ ".*-api"'

Count matching blocks:

wcl query config.wcl 'service' --count

Output as JSON:

wcl query config.wcl 'service | .port > 1024' --format json

Query recursively across a directory:

wcl query --recursive ./configs 'service | has(@deprecated)'

Filter by decorator argument:

wcl query config.wcl 'service | @tag.env == "prod"'