From 5dbc836106ef3a5914210dbb15af67d179067f8f Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 14 Dec 2018 14:01:37 +0100 Subject: [PATCH] pylightning: Merge option_values into options Suggested-by: Rusty Russell <@rustyrussell> Signed-off-by: Christian Decker --- contrib/pylightning/lightning/plugin.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/contrib/pylightning/lightning/plugin.py b/contrib/pylightning/lightning/plugin.py index a4c0579e4..2e5f13279 100644 --- a/contrib/pylightning/lightning/plugin.py +++ b/contrib/pylightning/lightning/plugin.py @@ -17,7 +17,6 @@ class Plugin(object): def __init__(self, stdout=None, stdin=None, autopatch=True): self.methods = {} self.options = {} - self.option_values = {} if not stdout: self.stdout = sys.stdout @@ -77,16 +76,18 @@ class Plugin(object): 'default': default, 'description': description, 'type': 'string', + 'value': None, } def get_option(self, name): - if name in self.option_values: - return self.option_values[name] - elif name in self.options: - return self.options[name]['default'] - else: + if name not in self.options: raise ValueError("No option with name {} registered".format(name)) + if self.options[name]['value'] is not None: + return self.options[name]['value'] + else: + return self.options[name]['default'] + def method(self, method_name, *args, **kwargs): """Decorator to add a plugin method to the dispatch table. @@ -209,7 +210,7 @@ class Plugin(object): self.rpc_filename = configuration['rpc-file'] self.lightning_dir = configuration['lightning-dir'] for name, value in options.items(): - self.option_values[name] = value + self.options[name]['value'] = value # Swap the registered `init` method handler back in and # re-dispatch