Refactor named plugin service/client endpoints

This commit is contained in:
sophia 2022-02-10 10:52:47 -06:00 committed by Paul Hinze
parent 153d218d68
commit 6c28de9ea9
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
4 changed files with 34 additions and 20 deletions

View File

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

View File

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

View File

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

View File

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