github.com/hashicorp/packer@v1.14.3/commands.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package main 5 6 import ( 7 "github.com/hashicorp/packer/command" 8 "github.com/mitchellh/cli" 9 ) 10 11 // Commands is the mapping of all the available Packer commands. 12 var Commands map[string]cli.CommandFactory 13 14 // CommandMeta is the Meta to use for the commands. This must be written 15 // before the CLI is started. 16 var CommandMeta *command.Meta 17 18 const ErrorPrefix = "e:" 19 const OutputPrefix = "o:" 20 21 func init() { 22 Commands = map[string]cli.CommandFactory{ 23 "build": func() (cli.Command, error) { 24 return &command.BuildCommand{Meta: *CommandMeta}, nil 25 }, 26 "console": func() (cli.Command, error) { 27 return &command.ConsoleCommand{ 28 Meta: *CommandMeta, 29 }, nil 30 }, 31 32 "execute": func() (cli.Command, error) { 33 return &command.ExecuteCommand{ 34 Meta: *CommandMeta, 35 }, nil 36 }, 37 38 "fix": func() (cli.Command, error) { 39 return &command.FixCommand{ 40 Meta: *CommandMeta, 41 }, nil 42 }, 43 44 "fmt": func() (cli.Command, error) { 45 return &command.FormatCommand{ 46 Meta: *CommandMeta, 47 }, nil 48 }, 49 50 "hcl2_upgrade": func() (cli.Command, error) { 51 return &command.HCL2UpgradeCommand{ 52 Meta: *CommandMeta, 53 }, nil 54 }, 55 56 "init": func() (cli.Command, error) { 57 return &command.InitCommand{ 58 Meta: *CommandMeta, 59 }, nil 60 }, 61 62 "inspect": func() (cli.Command, error) { 63 return &command.InspectCommand{ 64 Meta: *CommandMeta, 65 }, nil 66 }, 67 68 "plugins": func() (cli.Command, error) { 69 return &command.PluginsCommand{ 70 Meta: *CommandMeta, 71 }, nil 72 }, 73 74 "plugins installed": func() (cli.Command, error) { 75 return &command.PluginsInstalledCommand{ 76 Meta: *CommandMeta, 77 }, nil 78 }, 79 80 "plugins install": func() (cli.Command, error) { 81 return &command.PluginsInstallCommand{ 82 Meta: *CommandMeta, 83 }, nil 84 }, 85 86 "plugins remove": func() (cli.Command, error) { 87 return &command.PluginsRemoveCommand{ 88 Meta: *CommandMeta, 89 }, nil 90 }, 91 92 "plugins required": func() (cli.Command, error) { 93 return &command.PluginsRequiredCommand{ 94 Meta: *CommandMeta, 95 }, nil 96 }, 97 98 "validate": func() (cli.Command, error) { 99 return &command.ValidateCommand{ 100 Meta: *CommandMeta, 101 }, nil 102 }, 103 104 "version": func() (cli.Command, error) { 105 return &command.VersionCommand{ 106 Meta: *CommandMeta, 107 CheckFunc: commandVersionCheck, 108 }, nil 109 }, 110 111 // plugin is essentially an alias to the plugins command 112 // 113 // It is not meant to be documented or used outside of simple 114 // typos, as it's easy to write plugin instead of plugins, so 115 // we opted not to error, but silently alias the two writings. 116 "plugin": func() (cli.Command, error) { 117 return &command.PluginsCommand{ 118 Meta: *CommandMeta, 119 }, nil 120 }, 121 "plugin installed": func() (cli.Command, error) { 122 return &command.PluginsInstalledCommand{ 123 Meta: *CommandMeta, 124 }, nil 125 }, 126 "plugin install": func() (cli.Command, error) { 127 return &command.PluginsInstallCommand{ 128 Meta: *CommandMeta, 129 }, nil 130 }, 131 "plugin remove": func() (cli.Command, error) { 132 return &command.PluginsRemoveCommand{ 133 Meta: *CommandMeta, 134 }, nil 135 }, 136 "plugin required": func() (cli.Command, error) { 137 return &command.PluginsRequiredCommand{ 138 Meta: *CommandMeta, 139 }, nil 140 }, 141 } 142 }