Use mappers to extract string funcspec arguments

This commit is contained in:
sophia 2021-09-01 10:17:37 -05:00 committed by Paul Hinze
parent 434e613856
commit 0016baef36
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
3 changed files with 25 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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}")