From 608846408d58eba2f62cde0b28f8bcf7f28fb409 Mon Sep 17 00:00:00 2001 From: Malte Brodersen Date: Mon, 9 Oct 2017 21:39:54 +0200 Subject: [PATCH] add terraform --- src/beautifiers/index.coffee | 1 + src/beautifiers/terraformfmt.coffee | 24 +++++++++++++++ src/languages/index.coffee | 1 + src/languages/terraform.coffee | 20 +++++++++++++ src/options.json | 46 +++++++++++++++++++++++++++-- 5 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 src/beautifiers/terraformfmt.coffee create mode 100644 src/languages/terraform.coffee diff --git a/src/beautifiers/index.coffee b/src/beautifiers/index.coffee index b3e630c..6d14410 100644 --- a/src/beautifiers/index.coffee +++ b/src/beautifiers/index.coffee @@ -80,6 +80,7 @@ module.exports = class Beautifiers extends EventEmitter 'marko-beautifier' 'formatR' 'beautysh' + 'terraform' ] ### diff --git a/src/beautifiers/terraformfmt.coffee b/src/beautifiers/terraformfmt.coffee new file mode 100644 index 0000000..fd08d02 --- /dev/null +++ b/src/beautifiers/terraformfmt.coffee @@ -0,0 +1,24 @@ +### +Requires terraform installed +### + +"use strict" +Beautifier = require('./beautifier') + +module.exports = class Terraformfmt extends Beautifier + name: "terraformfmt" + link: "https://www.terraform.io/docs/commands/fmt.html" + isPreInstalled: false + + options: { + Terraform: true + } + + beautify: (text, language, options) -> + @run("terraform", [ + "fmt" + tempFile = @tempFile("input", text) + ]) + .then(=> + @readFile(tempFile) + ) diff --git a/src/languages/index.coffee b/src/languages/index.coffee index 9ea2e36..7cc1e5c 100644 --- a/src/languages/index.coffee +++ b/src/languages/index.coffee @@ -77,6 +77,7 @@ module.exports = class Languages "xml" "xtemplate" "yaml" + "terraform" ] ### diff --git a/src/languages/terraform.coffee b/src/languages/terraform.coffee new file mode 100644 index 0000000..16ad848 --- /dev/null +++ b/src/languages/terraform.coffee @@ -0,0 +1,20 @@ +module.exports = { + + name: "Terraform" + namespace: "terraform" + fallback: ['js'] + + ### + Supported Grammars + ### + grammars: [ + "Terraform" + ] + + ### + Supported extensions + ### + extensions: [ + "tf" + ] +} diff --git a/src/options.json b/src/options.json index 8767e0d..de2872e 100644 --- a/src/options.json +++ b/src/options.json @@ -4578,8 +4578,7 @@ "Lua" ], "extensions": [ - "lua", - "ttslua" + "lua" ], "properties": { "end_of_line": { @@ -6517,6 +6516,47 @@ "description": "Automatically beautify Rust files on save" } } + }, + "terraform": { + "title": "Terraform", + "type": "object", + "description": "Options for language Terraform", + "collapsed": true, + "beautifiers": [ + "terraformfmt" + ], + "grammars": [ + "Terraform" + ], + "extensions": [ + "tf" + ], + "properties": { + "disabled": { + "title": "Disable Beautifying Language", + "order": -3, + "type": "boolean", + "default": false, + "description": "Disable Rust Beautification" + }, + "default_beautifier": { + "title": "Default Beautifier", + "order": -2, + "type": "string", + "default": "terraformfmt", + "description": "Default Beautifier to be used for Terraform", + "enum": [ + "terraformfmt" + ] + }, + "beautify_on_save": { + "title": "Beautify On Save", + "order": -1, + "type": "boolean", + "default": false, + "description": "Automatically beautify Terraform files on save" + } + } }, "sass": { "title": "Sass", @@ -9377,4 +9417,4 @@ } } } -} \ No newline at end of file +}