From 6c28de9ea9ade12428178a94da025cc8f6de2e44 Mon Sep 17 00:00:00 2001 From: sophia Date: Thu, 10 Feb 2022 10:52:47 -0600 Subject: [PATCH] Refactor named plugin service/client endpoints --- plugins/commands/serve/client/guest.rb | 8 ++--- .../commands/serve/service/guest_service.rb | 15 +--------- plugins/commands/serve/util.rb | 1 + plugins/commands/serve/util/named_plugin.rb | 30 +++++++++++++++++++ 4 files changed, 34 insertions(+), 20 deletions(-) create mode 100644 plugins/commands/serve/util/named_plugin.rb diff --git a/plugins/commands/serve/client/guest.rb b/plugins/commands/serve/client/guest.rb index ae10e608d..8a324b5d7 100644 --- a/plugins/commands/serve/client/guest.rb +++ b/plugins/commands/serve/client/guest.rb @@ -5,6 +5,8 @@ module VagrantPlugins class Client class Guest < Client include CapabilityPlatform + include Util::NamedPlugin::Client + # Generate callback and spec for required arguments # # @return [SDK::FuncSpec, Proc] @@ -20,12 +22,6 @@ module VagrantPlugins def parent run_func end - - # @return [String] plugin name - def name - c = client.plugin_name(Empty.new) - c.name - end end end end diff --git a/plugins/commands/serve/service/guest_service.rb b/plugins/commands/serve/service/guest_service.rb index 4d07c95b2..a3cabcefb 100644 --- a/plugins/commands/serve/service/guest_service.rb +++ b/plugins/commands/serve/service/guest_service.rb @@ -6,6 +6,7 @@ module VagrantPlugins class GuestService < Hashicorp::Vagrant::Sdk::GuestService::Service include CapabilityPlatformService + include Util::NamedPlugin::Service def initialize(*args, **opts, &block) caps = Vagrant.plugin("2").local_manager.guest_capabilities @@ -83,20 +84,6 @@ module VagrantPlugins end end - def set_plugin_name(req, ctx) - logger.debug("setting plugin name to nothing 'cause i don't care") - Empty.new - end - - def plugin_name(req, ctx) - with_info(ctx, broker: broker) do |info| - logger.debug("returning plugin name #{info.plugin_name}") - SDK::PluginInfo::Name.new( - name: info.plugin_name - ) - end - end - def capability_arguments(args) target, direct = args nargs = direct.args.dup diff --git a/plugins/commands/serve/util.rb b/plugins/commands/serve/util.rb index 766d00f6a..d94b13f09 100644 --- a/plugins/commands/serve/util.rb +++ b/plugins/commands/serve/util.rb @@ -10,6 +10,7 @@ module VagrantPlugins autoload :HasLogger, Vagrant.source_root.join("plugins/commands/serve/util/has_logger").to_s autoload :HasMapper, Vagrant.source_root.join("plugins/commands/serve/util/has_mapper").to_s autoload :HasSeeds, Vagrant.source_root.join("plugins/commands/serve/util/has_seeds").to_s + autoload :NamedPlugin, Vagrant.source_root.join("plugins/commands/serve/util/named_plugin").to_s autoload :ServiceInfo, Vagrant.source_root.join("plugins/commands/serve/util/service_info").to_s autoload :UsageTracker, Vagrant.source_root.join("plugins/commands/serve/util/usage_tracker").to_s end diff --git a/plugins/commands/serve/util/named_plugin.rb b/plugins/commands/serve/util/named_plugin.rb new file mode 100644 index 000000000..4e23d0871 --- /dev/null +++ b/plugins/commands/serve/util/named_plugin.rb @@ -0,0 +1,30 @@ +module VagrantPlugins + module CommandServe + module Util + module NamedPlugin + module Service + def set_plugin_name(req, ctx) + # No opt + Empty.new + end + + def plugin_name(req, ctx) + with_info(ctx, broker: broker) do |info| + SDK::PluginInfo::Name.new( + name: info.plugin_name + ) + end + end + end + + module Client + # @return [String] plugin name + def name + c = client.plugin_name(Empty.new) + c.name + end + end + end + end + end +end