hq-rs

Crates.iohq-rs
lib.rshq-rs
version
sourcesrc
created_at2024-05-20 00:52:58.125649+00
updated_at2025-02-18 03:43:01.91201+00
descriptioncommand-line HCL processor
homepagehttps://github.com/miller-time/hq
repositoryhttps://github.com/miller-time/hq
max_upload_size
id1245317
Cargo.toml error:TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Russell (miller-time)

documentation

https://docs.rs/hq-rs/latest

README

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{"some_block_label"}.attr'
"value"
$ cat example.hcl | hq '.some_block{"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"
}

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:

$ 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"

You can delete entries in an HCL file like so:

$ cat example.hcl | hq delete '.nested_block.inner_block.value'
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:

$ hq delete -i -f example.hcl '.nested_block.inner_block.another_value'
Commit count: 95

cargo fmt