From f2ef8110bb383bf1e34a4f88af0ec82bd24925ce Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Thu, 4 Mar 2021 15:34:26 -0800 Subject: [PATCH] Accept command arguments and pass them when executing internal commands --- .../commands/serve/service/command_service.rb | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/plugins/commands/serve/service/command_service.rb b/plugins/commands/serve/service/command_service.rb index f73528cf8..08b310a0d 100644 --- a/plugins/commands/serve/service/command_service.rb +++ b/plugins/commands/serve/service/command_service.rb @@ -95,11 +95,16 @@ module VagrantPlugins def execute_spec(req, ctx) SDK::FuncSpec.new( + name: "execute_spec", args: [ SDK::FuncSpec::Value.new( type: "hashicorp.vagrant.sdk.Args.TerminalUI", name: "", ), + SDK::FuncSpec::Value.new( + type: "hashicorp.vagrant.sdk.Command.Arguments", + name: "", + ) ], result: [ SDK::FuncSpec::Value.new( @@ -113,8 +118,16 @@ module VagrantPlugins def execute(req, ctx) ServiceInfo.with_info(ctx) do |info| plugin_name = info.plugin_name - raw_terminal = req.args.first.value.value + raw_terminal = req.args.detect { |a| + a.type == "hashicorp.vagrant.sdk.Args.TerminalUI" + }&.value&.value + raw_args = req.args.detect { |a| + a.type == "hashicorp.vagrant.sdk.Command.Arguments" + }&.value&.value + + arguments = SDK::Command::Arguments.decode(raw_args) ui_client = Client::Terminal.terminal_arg_to_terminal_ui(raw_terminal) + ui = Vagrant::UI::RemoteUI.new(ui_client) env = Vagrant::Environment.new(ui: ui) @@ -123,11 +136,11 @@ module VagrantPlugins raise "Failed to locate command plugin for: #{plugin_name}" end cmd_klass = plugin.call - cmd = cmd_klass.new([], env) + cmd = cmd_klass.new(arguments.args.to_a, env) begin result = cmd.execute rescue => e - raise e.to_s + "\n" + e.backtrace.join("\n") + raise e.message.tr("\n", " ") # + "\n" + e.backtrace.join("\n") end SDK::Command::ExecuteResp.new(