Use mappers to extract string funcspec arguments
This commit is contained in:
parent
434e613856
commit
0016baef36
@ -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
|
||||
|
||||
22
plugins/commands/serve/mappers/capability.rb
Normal file
22
plugins/commands/serve/mappers/capability.rb
Normal 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
|
||||
@ -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}")
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user