-
Notifications
You must be signed in to change notification settings - Fork 15
Description
Problem
When working with swamp model data from the CLI, structured output often needs post-processing — parsing JSON responses, extracting fields, filtering arrays. Currently users reach for python3 -c "import sys,json; ..." or jq one-liners piped after --json output, which is clunky and creates a dependency on external tools.
This comes up constantly when:
- Inspecting model data attributes from
swamp data get - Filtering output from
swamp data list - Extracting specific fields from
swamp model method runresults - Chaining CLI commands where one step's output feeds the next
Proposed Solution
Ship a lightweight query/filter mechanism built into the swamp CLI itself. Options:
-
--query/-qflag on commands that emit JSON — a small expression language (CEL subset, jq-like path syntax, or JSONPath) to extract/filter fields inline. e.g.:swamp data get dev-vms latest --json -q '.attributes.vms[].domain'swamp data list dev-vms --json -q '.groups[].items[] | select(.name | contains("controller"))'
-
swamp querysubcommand that reads JSON from stdin and applies an expression, so it can be piped:swamp model method run dev-vms discover --json | swamp query '.data.attributes.vms | length'
-
Built-in
--formattemplates for common extractions (table, csv, specific fields).
Since swamp already has a CEL evaluator for workflow expressions, reusing that for CLI output queries would be a natural fit and avoid adding a new expression language.
Alternatives
- Require users to install
jq(common but not universal, especially on CI) - Keep relying on
python3 -cone-liners (verbose, error-prone) - Do nothing (status quo works but adds friction to every CLI interaction)