diff --git a/plugins/commands/serve/mappers.rb b/plugins/commands/serve/mappers.rb index 94f768b51..a724e711b 100644 --- a/plugins/commands/serve/mappers.rb +++ b/plugins/commands/serve/mappers.rb @@ -223,3 +223,4 @@ require Vagrant.source_root.join("plugins/commands/serve/mappers/target.rb").to_ require Vagrant.source_root.join("plugins/commands/serve/mappers/target_index.rb").to_s require Vagrant.source_root.join("plugins/commands/serve/mappers/terminal.rb").to_s require Vagrant.source_root.join("plugins/commands/serve/mappers/command.rb").to_s +require Vagrant.source_root.join("plugins/commands/serve/mappers/capability.rb").to_s diff --git a/plugins/commands/serve/mappers/capability.rb b/plugins/commands/serve/mappers/capability.rb new file mode 100644 index 000000000..da755e59f --- /dev/null +++ b/plugins/commands/serve/mappers/capability.rb @@ -0,0 +1,22 @@ +module VagrantPlugins + module CommandServe + class Mappers + # Extracts a string capability name from a Funcspec value + class NamedCapability < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: SDK::FuncSpec::Value) { |arg| + arg.type == "hashicorp.vagrant.sdk.Args.NamedCapability" && + !arg&.value&.value.nil? + } + end + super(inputs: inputs, output: String, func: method(:converter)) + end + + def converter(proto) + SDK::Args::NamedCapability.decode(proto.value.value).Capability + end + end + end + end +end diff --git a/plugins/commands/serve/service/guest_service.rb b/plugins/commands/serve/service/guest_service.rb index 149af76d6..19ca409bf 100644 --- a/plugins/commands/serve/service/guest_service.rb +++ b/plugins/commands/serve/service/guest_service.rb @@ -100,9 +100,8 @@ module VagrantPlugins def has_capability(req, ctx) ServiceInfo.with_info(ctx) do |info| - cap_name = req.args.detect { |a| - a.type == "hashicorp.vagrant.sdk.Args.NamedCapability" - }&.value&.value.strip.gsub("\b", "").gsub("\x05", "") + cap_name = mapper.funcspec_map(req).to_sym + plugin_name = info.plugin_name LOGGER.debug("checking for #{cap_name} capability in #{plugin_name}")