Crates.io | hq-rs |
lib.rs | hq-rs |
version | 0.13.0 |
source | src |
created_at | 2024-05-20 00:52:58.125649 |
updated_at | 2024-07-16 15:38:55.778008 |
description | command-line HCL processor |
homepage | https://github.com/miller-time/hq |
repository | https://github.com/miller-time/hq |
max_upload_size | |
id | 1245317 |
size | 42,235 |
hq
is a command-line HCL processor.
This will install an hq
binary on your system:
$ cargo install hq-rs
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"
Or read directly from a file by passing read -f
:
$ hq read -f example.hcl '.some_block'
some_block "some_block_label" {
attr = "value"
}
some_block "another_block_label" {
attr = "another_value"
}
You can modify HCL (even HCL that is formatted and contains comments) like so:
$ cat example.hcl | hq write '.fmt_block.first_formatted_field="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"
}
Modifications can also be written directly to a file by passing -i
(inline) and -f
(file):
$ hq write -i -f example.hcl '.fmt_block.first_formatted_field="something_written_inline"'
$ hq read -f example.hcl .fmt_block.first_formatted_field
"something_written_inline"