hcledit icon indicating copy to clipboard operation
hcledit copied to clipboard

Can this be used as jo for HCL?

Open nikolay opened this issue 2 years ago • 9 comments

https://manpages.org/jo

nikolay avatar Sep 26 '23 22:09 nikolay

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.

minamijoyo avatar Sep 27 '23 01:09 minamijoyo

The use case is creating valid HCL from shell scripts.

nikolay avatar Sep 27 '23 21:09 nikolay

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 avatar Sep 28 '23 08:09 antonbabenko

@antonbabenko Doesn't really work:

$ echo 'locals {}' | hcledit attribute append module.wrapper.source test --newline
locals {}

nikolay avatar Sep 28 '23 16:09 nikolay

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 avatar Sep 29 '23 09:09 antonbabenko

@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.

nikolay avatar Sep 29 '23 19:09 nikolay

Yes, there are some limitations around making root blocks. I usually make a file with a placeholder and then modify it.

antonbabenko avatar Sep 30 '23 08:09 antonbabenko

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.

nikolay avatar Sep 30 '23 17:09 nikolay

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.

minamijoyo avatar Oct 02 '23 09:10 minamijoyo