Skip to content
Permalink
Browse files

Support HCL in unparse

  • Loading branch information...
squaremo committed May 30, 2019
1 parent c03f303 commit 471a929733756a3461713cf3689e2caf6fc0b005
Showing with 41 additions and 0 deletions.
  1. +4 −0 pkg/std/parse_unparse.go
  2. +25 −0 tests/test-unparse.js
  3. +12 −0 tests/test-unparse.js.expected
@@ -53,6 +53,10 @@ func Unparse(jsonString []byte, format __std.Format) ([]byte, error) {
var buf bytes.Buffer
err := writeYAMLStream(&buf, jsonString, 2)
return buf.Bytes(), err
case __std.FormatHCL:
var buf bytes.Buffer
err := writeHCL(&buf, jsonString, 2)
return buf.Bytes(), err
}
return nil, fmt.Errorf(`Unsupported format for Unparse: %s`, __std.EnumNamesFormat[format])
}
@@ -15,3 +15,28 @@ log(jsons);
log('# YAML stream');
const yamls = unparse([{ yaml: 1 }, { yaml: 2 }], Format.YAMLStream);
log(yamls);

log('# HCL config');
const config = {
provider: {
github: {
organization: 'myorg',
},
},
github_membership: {
myorg_foo: {
username: 'foo',
role: 'admin',
},
},
};
const hcl = unparse(config, Format.HCL);
log(hcl);

log('# Unsupported format');
try {
const str = unparse({ foo: 2 }, Format.FromExtension);
log(str);
} catch (_) {
log('Unsupported format correctly errored.');
}
@@ -12,3 +12,15 @@ yaml: 1
---
yaml: 2

# HCL config
"provider" "github" {
"organization" = "myorg"
}

"github_membership" "myorg_foo" {
"username" = "foo"

"role" = "admin"
}
# Unsupported format
Unsupported format correctly errored.

0 comments on commit 471a929

Please sign in to comment.
You can’t perform that action at this time.