From fb5c2dd3395cb69b54ed31b707e2fa56a4a93c96 Mon Sep 17 00:00:00 2001 From: sophia Date: Wed, 1 Dec 2021 13:29:39 -0600 Subject: [PATCH] Add basis client module --- plugins/commands/serve/client.rb | 1 + plugins/commands/serve/client/basis.rb | 55 ++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 plugins/commands/serve/client/basis.rb diff --git a/plugins/commands/serve/client.rb b/plugins/commands/serve/client.rb index af687917e..0df0db03a 100644 --- a/plugins/commands/serve/client.rb +++ b/plugins/commands/serve/client.rb @@ -1,6 +1,7 @@ module VagrantPlugins module CommandServe module Client + autoload :Basis, Vagrant.source_root.join("plugins/commands/serve/client/basis").to_s autoload :Box, Vagrant.source_root.join("plugins/commands/serve/client/box").to_s autoload :BoxCollection, Vagrant.source_root.join("plugins/commands/serve/client/box_collection").to_s autoload :CapabilityPlatform, Vagrant.source_root.join("plugins/commands/serve/client/capability_platform").to_s diff --git a/plugins/commands/serve/client/basis.rb b/plugins/commands/serve/client/basis.rb new file mode 100644 index 000000000..150cc40bc --- /dev/null +++ b/plugins/commands/serve/client/basis.rb @@ -0,0 +1,55 @@ +module VagrantPlugins + module CommandServe + module Client + class Basis + prepend Util::ClientSetup + prepend Util::HasLogger + prepend Util::HasMapper + + # return [Sdk::Args::DataDir::Basis] + def data_dirs + resp = client.data_dir(Empty.new) + resp + end + + # return [String] + def data_dir + data_dirs.data_dir + end + + # @return [Terminal] + def ui + begin + Terminal.load( + client.ui(Google::Protobuf::Empty.new), + broker: @broker, + ) + rescue => err + raise "Failed to load terminal via project: #{err}" + end + end + + # @return [Host] + def host + h = client.host(Empty.new) + Host.load(h, broker: broker) + end + + # @param [List] the type of plugin to get + # @return [List] a list of plugin clients that match the type requested + def plugins(types) + plugins_response = client.plugins( + SDK::Basis::PluginsRequest.new(types: Array(types)) + ) + plugins = [] + plugins_response.plugins.each do |plg| + logger.debug("mappng plugin: #{plg}") + unany_plg = mapper.unany(plg.plugin) + plugins << mapper.map(unany_plg, broker) + end + plugins + end + end + end + end +end