diff --git a/command/fmt.go b/command/fmt.go index 359464518..b04310ad2 100644 --- a/command/fmt.go +++ b/command/fmt.go @@ -36,10 +36,10 @@ func (c *FormatCommand) ParseArgs(args []string) (*FormatArgs, int) { } args = flags.Args() - /*if len(args) != 1 { + if len(args) == 0 { flags.Usage() return &cfg, 1 - }*/ + } //cfg.Path = args[0] cfg.Paths = args diff --git a/hcl2template/formatter.go b/hcl2template/formatter.go index 571ed845d..541e0079a 100644 --- a/hcl2template/formatter.go +++ b/hcl2template/formatter.go @@ -121,7 +121,7 @@ func (f *HCL2Formatter) FormatNew(paths []string) (int, hcl.Diagnostics) { for _, path := range paths { s, err := os.Stat(path) - if err != nil { + /*if err != nil { diag := &hcl.Diagnostic{ Severity: hcl.DiagError, Summary: fmt.Sprintf("No file or directory at %s", path), @@ -129,24 +129,24 @@ func (f *HCL2Formatter) FormatNew(paths []string) (int, hcl.Diagnostics) { } diags = append(diags, diag) return 0, diags - } + }*/ - if !s.IsDir() { - fmtd := false + if err != nil || !s.IsDir() { + bytesModified, diags = f.formatFile(path, diags, bytesModified) + /*formatted := false if isHcl2FileOrVarFile(path) { bytesModified, diags = f.formatFile(path, diags, bytesModified) - fmtd = true + formatted = true } - if !fmtd { + if !formatted { diag := &hcl.Diagnostic{ Severity: hcl.DiagError, Summary: "Only .pkr.hcl and .pkrvars.hcl files can be processed with packer fmt", } diags = append(diags, diag) - continue - } + }*/ } else { fileInfos, err := os.ReadDir(path) if err != nil {