* Add packer fmt command This change adds a new command that allows users to format one or more HCL2 Packer configuration template files. Related to: #9174 * command/fmt: Add check flag Packer's fmt command now supports a check flag that will output the name of any file that would be changed by the HCL2 formatting engine. The check flag is mutually exclusive with the write flag and will only check if formatting is needed. The update write flag will now overwrite the source files with the newly formatted HCL2 source unless the `-write=false` or `-check` is passed at the command line. * Returns a diagnostic error if Format is unable to show a diff - equivalent to `terraform fmt` * Updates testing to run against #Format and not the private methods of the HCL2Formatter; fixes ShowDiff test failure on Windows * Updates comments for exported functions * Add docs for fmt command
73 lines
1.5 KiB
Go
73 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/hashicorp/packer/command"
|
|
"github.com/mitchellh/cli"
|
|
)
|
|
|
|
// Commands is the mapping of all the available Packer commands.
|
|
var Commands map[string]cli.CommandFactory
|
|
|
|
// CommandMeta is the Meta to use for the commands. This must be written
|
|
// before the CLI is started.
|
|
var CommandMeta *command.Meta
|
|
|
|
const ErrorPrefix = "e:"
|
|
const OutputPrefix = "o:"
|
|
|
|
func init() {
|
|
Commands = map[string]cli.CommandFactory{
|
|
"build": func() (cli.Command, error) {
|
|
return &command.BuildCommand{Meta: *CommandMeta}, nil
|
|
},
|
|
"console": func() (cli.Command, error) {
|
|
return &command.ConsoleCommand{
|
|
Meta: *CommandMeta,
|
|
}, nil
|
|
},
|
|
|
|
"fix": func() (cli.Command, error) {
|
|
return &command.FixCommand{
|
|
Meta: *CommandMeta,
|
|
}, nil
|
|
},
|
|
|
|
"fmt": func() (cli.Command, error) {
|
|
return &command.FormatCommand{
|
|
Meta: *CommandMeta,
|
|
}, nil
|
|
},
|
|
|
|
"hcl2_upgrade": func() (cli.Command, error) {
|
|
return &command.HCL2UpgradeCommand{
|
|
Meta: *CommandMeta,
|
|
}, nil
|
|
},
|
|
|
|
"inspect": func() (cli.Command, error) {
|
|
return &command.InspectCommand{
|
|
Meta: *CommandMeta,
|
|
}, nil
|
|
},
|
|
|
|
"plugin": func() (cli.Command, error) {
|
|
return &command.PluginCommand{
|
|
Meta: *CommandMeta,
|
|
}, nil
|
|
},
|
|
|
|
"validate": func() (cli.Command, error) {
|
|
return &command.ValidateCommand{
|
|
Meta: *CommandMeta,
|
|
}, nil
|
|
},
|
|
|
|
"version": func() (cli.Command, error) {
|
|
return &command.VersionCommand{
|
|
Meta: *CommandMeta,
|
|
CheckFunc: commandVersionCheck,
|
|
}, nil
|
|
},
|
|
}
|
|
}
|