{"id":18639170,"url":"https://github.com/rjeczalik/refmt","last_synced_at":"2025-04-11T10:32:34.950Z","repository":{"id":57501394,"uuid":"93301465","full_name":"rjeczalik/refmt","owner":"rjeczalik","description":"Reformat HCL ⇄ JSON ⇄ YAML.","archived":false,"fork":false,"pushed_at":"2022-04-08T01:28:17.000Z","size":201,"stargazers_count":25,"open_issues_count":1,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-06T17:36:40.398Z","etag":null,"topics":["hcl","json","kubectl","terraform","yaml"],"latest_commit_sha":null,"homepage":"https://rafal.dev/refmt","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rjeczalik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-04T08:53:09.000Z","updated_at":"2024-01-18T10:46:01.000Z","dependencies_parsed_at":"2022-08-28T19:41:33.946Z","dependency_job_id":null,"html_url":"https://github.com/rjeczalik/refmt","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjeczalik%2Frefmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjeczalik%2Frefmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjeczalik%2Frefmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjeczalik%2Frefmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rjeczalik","download_url":"https://codeload.github.com/rjeczalik/refmt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223466499,"owners_count":17149770,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hcl","json","kubectl","terraform","yaml"],"created_at":"2024-11-07T05:45:56.125Z","updated_at":"2024-11-07T05:45:56.844Z","avatar_url":"https://github.com/rjeczalik.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# refmt [![GoDoc](https://godoc.org/github.com/rjeczalik/refmt?status.png)](https://godoc.org/github.com/rjeczalik/refmt) [![Build Status](https://img.shields.io/travis/rjeczalik/refmt/master.svg)](https://travis-ci.org/rjeczalik/refmt \"linux_amd64\") [![Build status](https://img.shields.io/appveyor/ci/rjeczalik/refmt.svg)](https://ci.appveyor.com/project/rjeczalik/refmt \"windows_amd64\")\nReformat HCL ⇄ JSON and HCL ⇄ YAML.\n\n### install\n\n```\n$ go get github.com/rjeczalik/refmt\n```\n\n### usage\n\n```\nusage:\n\n\trefmt [-t type] INPUT_FILE|\"-\" OUTPUT_FILE|\"-\"\n\nConverts from one encoding to another. Supported formats (and their file extensions):\n\n\t- HCL (.hcl or .tf)\n\t- JSON (.json)\n\t- YAML (.yaml or .yml)\n\nIf INPUT_FILE's extension is not recognized or INPUT_FILE is \"-\" (stdin),\nrefmt will try to guess input format.\n\nIf OUTPUT_FILE is \"-\" (stdout), destination format type is required to be\npassed with -t flag.\n\n\trefmt [-t type] merge ORIGINAL_FILE|\"-\" MIXIN_FILE|\"-\" OUTPUT_FILE|\"-\"\n\nMerges the object defined in ORIGINAL_FILE with the object from MIXIN_FILE, writing\nthe resulting object to the OUTPUT_FILE.\n\nThe ORIGINAL_FILE, MIXIN_FILE and OUTPUT_FILE can have different encodings.\n\nIf ORIGINAL_FILE's extension is not recognized or ORIGINAL_FILE is \"-\" (stdin),\nrefmt will try to guess original format.\n\nIf ORIGINAL_FILE does not exist or is empty, refmt is going to use empty\nobject instead.\n\nIf MIXIN_FILE's extension is not recognized or MIXIN_FILE is \"-\" (stdin),\nrefmt will try to guess mixin format.\n\nIf OUTPUT_FILE is \"-\" (stdout), destination format type is required to be\npassed with -t flag.\n```\n\n### docker usage\n\n```\n# build the refmt image\ndocker build -t refmt .\n\n# convert test.yml to hcl\ncat test.yml | docker run -i --rm refmt -t hcl - -\n```\n\n\n### examples\n\n```\n$ refmt -t yaml main.yaml -\n```\n```yaml\nprovider:\n  aws:\n    access_key: ${var.aws_access_key}\n    secret_key: ${var.aws_secret_key}\nresource:\n  aws_instance:\n    aws-instance:\n      instance_type: t2.nano\n      user_data: echo \"hello world!\" \u003e\u003e /tmp/helloworld.txt\n```\n```\n$ refmt main.yaml main.json\n```\n```json\n{\n        \"provider\": {\n                \"aws\": {\n                        \"access_key\": \"${var.aws_access_key}\",\n                        \"secret_key\": \"${var.aws_secret_key}\"\n                }\n        },\n        \"resource\": {\n                \"aws_instance\": {\n                        \"aws-instance\": {\n                                \"instance_type\": \"t2.nano\",\n                                \"user_data\": \"echo \\\"hello world!\\\" \u003e\u003e /tmp/helloworld.txt\"\n                        }\n                }\n        }\n}\n```\n```hcl\n$ refmt main.json main.hcl\n```\n```\nprovider \"aws\" {\n  access_key = \"${var.aws_access_key}\"\n  secret_key = \"${var.aws_secret_key}\"\n}\n\nresource \"aws_instance\" \"aws-instance\" {\n  instance_type = \"t2.nano\"\n  user_data = \"echo \\\"hello world!\\\" \u003e\u003e /tmp/helloworld.txt\"\n}\n```\n\n#### pretty reformat in-place\n\n```\n$ refmt main.tf.json main.tf.json\n```\n\n### merge configurations\n\n```yaml\n$ cat ~/.kube/config\napiVersion: v1\nclusters:\n- cluster:\n    certificate-authority: /Volumes/rjk.io/.kube/ca.pem\n    server: https://178.0.20.1\n  name: default-cluster\ncontexts:\n- context:\n    cluster: default-cluster\n    user: default-admin\n  name: default-system\ncurrent-context: default-system\nkind: Config\npreferences: {}\nusers:\n- name: default-admin\n  user:\n    client-certificate: /Volumes/rjk.io/.kube/admin.pem\n    client-key: /Volumes/rjk.io/.kube/admin-key.pem\n```\n```yaml\n$ cat \u003e\u003eanother-cluster \u003c\u003cEOF\napiVersion: v1\nclusters:\n- cluster:\n    certificate-authority: /Volumes/rjk.io/.kube/another-ca.pem\n    server: https://10.0.0.1\n  name: another-cluster\ncontexts:\n- context:\n    cluster: another-cluster\n    user: another-admin\n  name: another-system\ncurrent-context: another-system\nkind: Config\npreferences: {}\nusers:\n- name: another-admin\n  user:\n    client-certificate: /Volumes/rjk.io/.kube/another-admin.pem\n    client-key: /Volumes/rjk.io/.kube/another-admin-key.pem\nEOF\n```\n```bash\n$ refmt merge -t yaml ~/.kube/config ./another-cluster -\n```\n```yaml\napiVersion: v1\nclusters:\n- cluster:\n    certificate-authority: /Volumes/rjk.io/.kube/ca.pem\n    server: https://178.0.20.1\n  name: default-cluster\n- cluster:\n    certificate-authority: /Volumes/rjk.io/.kube/another-ca.pem\n    server: https://10.0.0.1\n  name: another-cluster\ncontexts:\n- context:\n    cluster: default-cluster\n    user: default-admin\n  name: default-system\n- context:\n    cluster: another-cluster\n    user: another-admin\n  name: another-system\ncurrent-context: another-system\nkind: Config\npreferences: {}\nusers:\n- name: default-admin\n  user:\n    client-certificate: /Volumes/rjk.io/.kube/admin.pem\n    client-key: /Volumes/rjk.io/.kube/admin-key.pem\n- name: another-admin\n  user:\n    client-certificate: /Volumes/rjk.io/.kube/another-admin.pem\n    client-key: /Volumes/rjk.io/.kube/another-admin-key.pem\n```\n\n### todo\n\n- inline docs\n- fix hcl marshaling:\n  - fix excessive newlines\n  - fix excessive quotes\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frjeczalik%2Frefmt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frjeczalik%2Frefmt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frjeczalik%2Frefmt/lists"}