https://github.com/miller-time/hq
  
  
    command-line HCL processor 
    https://github.com/miller-time/hq
  
        Last synced: 8 days ago 
        JSON representation
    
command-line HCL processor
- Host: GitHub
 - URL: https://github.com/miller-time/hq
 - Owner: miller-time
 - License: mit
 - Created: 2024-05-15T22:43:21.000Z (over 1 year ago)
 - Default Branch: main
 - Last Pushed: 2025-03-23T01:14:42.000Z (8 months ago)
 - Last Synced: 2025-07-29T03:17:54.941Z (3 months ago)
 - Language: Rust
 - Size: 82 KB
 - Stars: 7
 - Watchers: 1
 - Forks: 4
 - Open Issues: 2
 - 
            Metadata Files:
            
- Readme: README.md
 - License: LICENSE
 
 
Awesome Lists containing this project
- trackawesomelist - hq (⭐3) - command-line HCL processor (Recently Updated / [Feb 10, 2025](/content/2025/02/10/README.md))
 - awesome-tf - hq - command-line HCL processor (Tools / Community providers)
 
README
          # hq
[](https://github.com/miller-time/hq/actions/workflows/rust.yml)
[](https://crates.io/crates/hq-rs)
[](https://docs.rs/hq-rs/latest)
`hq` is a command-line HCL processor.
## install
This will install an `hq` binary on your system:
```sh
$ cargo install hq-rs
```
## usage
Here is an example HCL file:
```hcl
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:
```sh
$ cat example.hcl | hq '.some_attr'
```
```hcl
{
  foo = [
    1,
    2
  ]
  bar = true
}
```
```sh
$ cat example.hcl | hq '.some_attr.foo'
```
```hcl
[
  1,
  2
]
```
```sh
$ cat example.hcl | hq '.some_block'
```
```hcl
some_block "some_block_label" {
  attr = "value"
}
some_block "another_block_label" {
  attr = "another_value"
}
```
```sh
$ cat example.hcl | hq '.some_block{"some_block_label"}.attr'
```
```hcl
"value"
```
```sh
$ cat example.hcl | hq '.some_block{"another_block_label"}.attr'
```
```hcl
"another_value"
```
Or read directly from a file by passing `read -f`:
```sh
$ hq read -f example.hcl '.some_block'
```
```hcl
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:
```sh
$ cat example.hcl | hq write '.fmt_block.first_formatted_field="something_new"'
```
```hcl
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"
}
nested_block {
    inner_block {
        value = "deep"
        another_value = "nested"
    }
}
```
Modifications can also be written directly to a file by passing `-i`/`--inline`
and `-f`/`--file`:
```sh
$ hq write -i -f example.hcl '.fmt_block.first_formatted_field="something_written_inline"'
```
```sh
$ hq read -f example.hcl .fmt_block.first_formatted_field
"something_written_inline"
```
You can delete entries in an HCL file like so:
```sh
$ cat example.hcl | hq delete '.nested_block.inner_block.value'
```
```hcl
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  = "fmt_value"
    second_formatted_field = "second_value"
}
nested_block {
    inner_block {
        another_value = "nested"
    }
}
```
Or you can delete entries from a file by passing `-i`/`--inline` and `-f`/`--file`:
```sh
$ hq delete -i -f example.hcl '.nested_block.inner_block.another_value'
```