From 05f6a62399d5c178493dbdb8dd2c2d2a1b7ae5b5 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Fri, 25 Sep 2020 16:07:41 -0700 Subject: [PATCH] command/fmt: Factor out the actual formatting Previously formatting was just a simple wrapper around hclwrite.Format. That remains true here, but the call is factored out into a separate method in preparation for making it also do some Terraform-specific cleanups in a future commit. --- command/fmt.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/command/fmt.go b/command/fmt.go index 6c6b31f043..b95b57a19f 100644 --- a/command/fmt.go +++ b/command/fmt.go @@ -176,7 +176,7 @@ func (c *FmtCommand) processFile(path string, r io.Reader, w io.Writer, isStdout return diags } - result := hclwrite.Format(src) + result := c.formatSourceCode(src) if !bytes.Equal(src, result) { // Something was changed @@ -266,6 +266,12 @@ func (c *FmtCommand) processDir(path string, stdout io.Writer) tfdiags.Diagnosti return diags } +// formatSourceCode is the formatting logic itself, applied to each file that +// is selected (directly or indirectly) on the command line. +func (c *FmtCommand) formatSourceCode(src []byte) []byte { + return hclwrite.Format(src) +} + func (c *FmtCommand) Help() string { helpText := ` Usage: terraform fmt [options] [DIR]