jihchi / kq

A jq-like CLI tool that allows querying and transforming KDL documents directly from the command line

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implement `Map Operator`

jihchi opened this issue · comments

Reference: https://github.com/kdl-org/kdl/blob/1.0.0/QUERY-SPEC.md#map-operator

Modified from QUERY-SPEC.md)

$ cat example.kdl
package {
    name "foo"
    version "1.0.0"
    dependencies platform="windows" {
        winapi "1.0.0" path="./crates/my-winapi-fork"
    }
    dependencies {
        miette "2.0.0" dev=true
    }
}

$ cat example.kdl | kq "package name => val()"
["foo"]

$ cat example.kdl | kq "dependencies[platform] => platform"
["windows"]

$ cat example.kdl | kq "dependencies > [] => (name(), val(), path)"
[("winapi", "1.0.0", "./crates/my-winapi-fork"), ("miette", "2.0.0", None)]

$ cat example.kdl | kq "dependencies > [] => (name(), values(), props())"
[("winapi", ["1.0.0"], {"platform": "windows"}), ("miette", ["2.0.0"], {"dev": true})]

FYI the map operator is going away completely with the next KQL spec, but you might want to come up with something that replaces it?