#hcl #processor #command-line #file #hq

bin+lib hq-rs

命令行HCL处理器

16个版本 (破坏性更新)

0.13.0 2024年7月16日
0.11.1 2024年7月12日

123配置

Download history 256/week @ 2024-05-14 148/week @ 2024-05-21 130/week @ 2024-05-28 37/week @ 2024-06-04 508/week @ 2024-06-11 248/week @ 2024-06-18 172/week @ 2024-06-25 96/week @ 2024-07-02 238/week @ 2024-07-09 119/week @ 2024-07-16 92/week @ 2024-07-23

每月449次下载

MIT 许可证

21KB
434

hq

ci crate docs

hq 是一个命令行HCL处理器。

安装

这将将在您的系统上安装 hq 二进制文件

$ cargo install hq-rs

用法

以下是一个HCL文件的示例

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

some_block "some_block_label" {
    attr = "value"
}

some_block "another_block_label" {
    attr = "another_value"
}

您可以通过这种方式查询HCL文件中的属性(和块)

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

或者通过传递 read -f 从文件中直接读取

$ hq read -f example.hcl '.some_block'
some_block "some_block_label" {
  attr = "value"
}
some_block "another_block_label" {
  attr = "another_value"
}

您还可以这样修改HCL(即使是格式化且包含注释的HCL)

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

修改也可以通过传递 -i(内联)和 -f(文件)直接写入文件

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

依赖项

~7.5MB
~134K SLoC