MCPcopy
hub / github.com/hashicorp/packer / RunContext

Method RunContext

command/execute.go:116–170  ·  view source on GitHub ↗
(args *ExecuteArgs)

Source from the content-addressed store, hash-verified

114}
115
116func (c *ExecuteCommand) RunContext(args *ExecuteArgs) int {
117 // Plugin will match something like "packer-builder-amazon-ebs"
118 parts := pluginRegexp.FindStringSubmatch(args.CommandType)
119 if len(parts) != 3 {
120 c.Ui.Error(c.Help())
121 return 1
122 }
123 pluginType := parts[1] // capture group 1 (builder|post-processor|provisioner)
124 pluginName := parts[2] // capture group 2 (.+)
125
126 server, err := plugin.Server()
127 if err != nil {
128 c.Ui.Error(fmt.Sprintf("Error starting plugin server: %s", err))
129 return 1
130 }
131
132 if args.UseProtobuf {
133 server.UseProto = true
134 }
135
136 switch pluginType {
137 case "builder":
138 builder, found := Builders[pluginName]
139 if !found {
140 c.Ui.Error(fmt.Sprintf("Could not load builder: %s", pluginName))
141 return 1
142 }
143 server.RegisterBuilder(builder)
144 case "provisioner":
145 provisioner, found := Provisioners[pluginName]
146 if !found {
147 c.Ui.Error(fmt.Sprintf("Could not load provisioner: %s", pluginName))
148 return 1
149 }
150 server.RegisterProvisioner(provisioner)
151 case "post-processor":
152 postProcessor, found := PostProcessors[pluginName]
153 if !found {
154 c.Ui.Error(fmt.Sprintf("Could not load post-processor: %s", pluginName))
155 return 1
156 }
157 server.RegisterPostProcessor(postProcessor)
158 case "datasource":
159 datasource, found := Datasources[pluginName]
160 if !found {
161 c.Ui.Error(fmt.Sprintf("Could not load datasource: %s", pluginName))
162 return 1
163 }
164 server.RegisterDatasource(datasource)
165 }
166
167 server.Serve()
168
169 return 0
170}
171
172func (*ExecuteCommand) Help() string {
173 helpText := `

Callers 1

RunMethod · 0.95

Calls 2

HelpMethod · 0.95
ErrorMethod · 0.65

Tested by

no test coverage detected