Add mappers for loading command client

This commit is contained in:
Chris Roberts 2021-12-17 14:58:15 -08:00 committed by Paul Hinze
parent 23c99b5806
commit 3f7b7ee65a
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0

View File

@ -17,6 +17,38 @@ module VagrantPlugins
SDK::Command::Arguments.decode(proto.value.value)
end
end
class CommandProtoFromSpec < Mapper
def initialize
super(
inputs: [Input.new(type: SDK::FuncSpec::Value) { |arg|
arg.type == "hashicorp.vagrant.sdk.Args.Command" &&
!arg&.value&.value.nil?
}
],
output: SDK::Args::Command,
func: method(:converter)
)
end
def converter(fv)
SDK::Args::Command.decode(fv.value.value)
end
end
class CommandFromProto < Mapper
def initialize
inputs = [].tap do |i|
i << Input.new(type: SDK::Args::Command)
i << Input.new(type: Broker)
end
super(inputs: inputs, output: Client::Command, func: method(:converter))
end
def converter(proto, broker)
Client::Command.load(proto, broker: broker)
end
end
end
end
end