dasel icon indicating copy to clipboard operation
dasel copied to clipboard

Support hcl files

Open josegonzalez opened this issue 4 years ago • 23 comments

Is your feature request related to a problem? Please describe.

HCL is a format commonly used for hashicorp tools. It would be great to add direct support for them in dasel.

Describe the solution you'd like

Support HCL v2.

Describe alternatives you've considered

The alternative is not supporting HCL, which is currently the case :)

Additional context

I would like this so that I can add better support for Nomad in the Dokku PaaS.

josegonzalez avatar Feb 26 '21 20:02 josegonzalez

I'm always open to supporting new file formats, as long as they play nicely with other implementations.

I will take a look at HCL 2 and get back to you on this soon.

Thank you for your interest in dasel 🙂

TomWright avatar Feb 27 '21 04:02 TomWright

Hey @josegonzalez,

This looks like it will be a longer term feature since I'll need to write some logic to parse hcl documents into a generic map[string]interface{}.

Short term it looks like you can use a combination of dasel and hcl2json to read hcl documents with dasel.

I'll leave this issue open so I can work on it when I have the time.

TomWright avatar Mar 02 '21 12:03 TomWright

@TomWright I've been using hcl2json with jq but hoped that I can use just one. HCL is widely popular in the DevOps world, so, it would great if it's natively supported.

nikolay avatar Mar 12 '21 06:03 nikolay

Thank you @TomWright for looking into this. I very much appreciate it and realize that development of the functionality may not be forthcoming.

josegonzalez avatar Mar 12 '21 08:03 josegonzalez

@nikolay I appreciate that and can see the benefit. I'm not saying it's not going to happen, just that I will have to work on it over time rather than a quick change now

TomWright avatar Mar 12 '21 09:03 TomWright

It looks like I can import and directly use hcl2json from my code to make that conversion.

This will allow me to add select support relatively easily, but does not (to my knowledge) allow me to convert JSON -> HCL in order for put commands to work.

TomWright avatar Mar 12 '21 09:03 TomWright

Maybe useful for turning a json byte array to hcl? https://github.com/hashicorp/hcl/blob/main/json/public.go#L20

josegonzalez avatar Mar 12 '21 10:03 josegonzalez

That looks promising.

I also found this repo although it is a little out of data: https://github.com/kvz/json2hcl/blob/master/main.go I'm not sure if it's for use with hcl v1 or v2.

TomWright avatar Mar 12 '21 11:03 TomWright

That repo is hclv1. Maybe supporting either via a flag works.

josegonzalez avatar Mar 12 '21 17:03 josegonzalez

By the way, there's a tool like jq just for HCL, but it also only supports v1 (for now): hcql.

nikolay avatar Mar 12 '21 19:03 nikolay

Are we interested in HCL v1, v2 or both?

To save on mass comment replies here maybe add a 👍 for v1 and a 👎 for v2.

TomWright avatar Mar 18 '21 16:03 TomWright

Thanks for all the feedback here.

I am currently reworking the encoding/decoding of all supported formats here: https://github.com/TomWright/dasel/pull/289

Once that is done I will use have a crack at implementing parsers for HCL V2.

TomWright avatar Jan 24 '23 19:01 TomWright