#hcl #processor #command-line #hq

bin+lib hq-rs

command-line HCL processor

8 breaking releases

new 0.9.0 Jun 15, 2024
0.7.0 Jun 11, 2024

#9 in #hcl

Download history 369/week @ 2024-05-17 35/week @ 2024-05-24 145/week @ 2024-05-31 285/week @ 2024-06-07

834 downloads per month

MIT license

17KB
374 lines

hq

ci crate docs

hq is a command-line HCL processor.

install

This will install an hq binary on your system:

$ cargo install hq-rs

usage

Here is an example HCL file:

some_attr = {
    foo = [1, 2]
    bar = true
}

some_block "some_block_label" {
    attr = "value"
}

some_block "another_block_label" {
    attr = "another_value"
}

You can query the attribute(s) and block(s) in an HCL file like so:

$ cat example.hcl | hq '.some_attr'
{
  foo = [
    1,
    2
  ]
  bar = true
}
$ cat example.hcl | hq '.some_attr.foo'
[
  1,
  2
]
$ cat example.hcl | hq '.some_block'
some_block "some_block_label" {
  attr = "value"
}
some_block "another_block_label" {
  attr = "another_value"
}
$ cat example.hcl | hq '.some_block[label="some_block_label"].attr'
"value"
$ cat example.hcl | hq '.some_block[label="another_block_label"].attr'
"another_value"

You can modify HCL (even HCL that is formatted and contains comments) like so:

$ cat example.hcl | hq '.fmt_block.first_formatted_field' write '"something_new"'
some_attr = {
    foo = [1, 2]
    bar = true
}

some_block "some_block_label" {
    attr = "value"
}

some_block "another_block_label" {
    attr = "another_value"
}

# this is a block comment
fmt_block "fmt_label" {
    # this is a body comment
    # this is another body comment

    # this is a third body comment
    first_formatted_field  = "something_new"
    second_formatted_field = "second_value"
}

Dependencies

~7.5MB
~136K SLoC