1
0

plugin commands: load the plugin in func_wrapper

This commit is contained in:
ThomasV
2025-03-16 12:25:59 +01:00
parent 51890fd0b5
commit d2fa404e06
2 changed files with 8 additions and 5 deletions

View File

@@ -1574,6 +1574,9 @@ def plugin_command(s, plugin_name):
@command(s)
@wraps(func)
async def func_wrapper(*args, **kwargs):
cmd_runner = args[0] # type: Commands
daemon = cmd_runner.daemon
kwargs['plugin'] = daemon._plugins.get_plugin(plugin_name)
return await func(*args, **kwargs)
setattr(Commands, name, func_wrapper)
return func_wrapper
@@ -1838,6 +1841,8 @@ def get_parser():
if optname in ['wallet_path', 'wallet']:
add_wallet_option(p)
continue
if optname in ['plugin']:
continue
a, help = command_options[optname]
b = '--' + optname
action = "store_true" if default is False else 'store'

View File

@@ -7,16 +7,14 @@ if TYPE_CHECKING:
plugin_name = "labels"
@plugin_command('w', plugin_name)
async def push(self: 'Commands', wallet=None) -> int:
async def push(self: 'Commands', plugin: 'LabelsPlugin' = None, wallet=None) -> int:
""" push labels to server """
plugin: 'LabelsPlugin' = self.daemon._plugins.get_plugin(plugin_name)
return await plugin.push_thread(wallet)
@plugin_command('w', plugin_name)
async def pull(self: 'Commands', wallet=None) -> int:
async def pull(self: 'Commands', plugin: 'LabelsPlugin' = None, wallet=None) -> int:
""" pull labels from server """
assert wallet is not None
plugin: 'LabelsPlugin' = self.daemon._plugins.get_plugin(plugin_name)
return await plugin.pull_thread(wallet, force=False)