hcledit
hcledit copied to clipboard
Can this be used as jo for HCL?
https://manpages.org/jo
Could you describe your use case and what feature you expect? I have not used jo before, so I'm unsure what you are trying.
The use case is creating valid HCL from shell scripts.
We call hcledit to manage HCL files in shell scripts like this:
# Create content of temporary main.tf file
hcledit attribute append module.wrapper.source "\"${relative_source_path}${module_dir}\"" --newline -f "$tmp_file_tf" -u
hcledit attribute append module.wrapper.for_each var.items --newline -f "$tmp_file_tf" -u
https://github.com/antonbabenko/pre-commit-terraform/blob/66a1469a7c7954d8469d7a6f79f4ffb8c9ae09bf/hooks/terraform_wrapper_module_for_each.sh#L350-L352
I am unsure what else jo offers but hcledit does not.
@antonbabenko Doesn't really work:
$ echo 'locals {}' | hcledit attribute append module.wrapper.source test --newline
locals {}
Works for me:
$ echo 'locals {}' | hcledit attribute append locals.test "\"test\"" --newline
locals {
test = "test"
}
The syntax can be a bit tricky to get right (especially for deeply nested structures).
@antonbabenko But I want to add a new element in the root. We need the equivalent of jo and eventually jq so that HCL becomes a first-class citizen and eliminate the need for temporary files.
Yes, there are some limitations around making root blocks. I usually make a file with a placeholder and then modify it.
Sorry, I know everything's possible, but the idea I brought up, jo is the tool's ergonomics. Sadly, there's no sane JSON to HCL converter that outputs Terraform-like HCL, not just a twisted version of the JSON. A valid JSON is a valid HCL, so those conversion tools are useless unless the tool converts JSON to readable and meaningful like what every one of us writes for Terraform.
What I understand is that apparently you like the comfort of jo, but I don't know how you want to improve hcledit specifically. Unless you can analyze the ergonomics of jo and make more specific requests, I don't know what to do.