plugins: add 'flag' type for plugin options

Updates the plugin docs to include more detailed info about how options
work.

Changelog-Added: Plugins: 'flag'-type option now available.
This commit is contained in:
lisa neigut
2020-03-16 20:34:35 -05:00
committed by Rusty Russell
parent a08905c344
commit 42cce55b45
7 changed files with 111 additions and 7 deletions

View File

@@ -250,8 +250,8 @@ class Plugin(object):
"Name {} is already used by another option".format(name)
)
if opt_type not in ["string", "int", "bool"]:
raise ValueError('{} not in supported type set (string, int, bool)')
if opt_type not in ["string", "int", "bool", "flag"]:
raise ValueError('{} not in supported type set (string, int, bool, flag)')
self.options[name] = {
'name': name,
@@ -261,6 +261,15 @@ class Plugin(object):
'value': None,
}
def add_flag_option(self, name, description):
"""Add a flag option that we'd like to register with lightningd.
Needs to be called before `Plugin.run`, otherwise we might not
end up getting it set.
"""
self.add_option(name, None, description, opt_type="flag")
def get_option(self, name):
if name not in self.options:
raise ValueError("No option with name {} registered".format(name))