Skip to content

Commit 0df9754

Browse files
committed
lightningd: don't simply ignore defaults on flags, deprecate.
Changelog-Deprecated: Plugins: `default` no longer accepted on `flag` type parameters (it was silently ignored, so just don't set it). Signed-off-by: Rusty Russell <[email protected]>
1 parent b9270c5 commit 0df9754

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

contrib/pyln-client/pyln/client/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ def _getmanifest(self, **kwargs) -> JSONType:
912912
m["long_description"] = method.long_desc
913913

914914
manifest = {
915-
'options': list(self.options.values()),
915+
'options': list({k: v for k, v in d.items() if v is not None} for d in self.options.values()),
916916
'rpcmethods': methods,
917917
'subscriptions': list(self.subscriptions.keys()),
918918
'hooks': hooks,

doc/PLUGINS.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,12 @@ There are currently four supported option 'types':
207207
- string: a string
208208
- bool: a boolean
209209
- int: parsed as a signed integer (64-bit)
210-
- flag: no-arg flag option. Is boolean under the hood. Defaults to false.
210+
- flag: no-arg flag option. Presented as `true` if config specifies it.
211211

212212
In addition, string and int types can specify `"multi": true` to indicate
213213
they can be specified multiple times. These will always be represented in
214-
`init` as a (possibly empty) JSON array.
214+
`init` as a (possibly empty) JSON array. "multi" flag types do not make
215+
sense.
215216

216217
Nota bene: if a `flag` type option is not set, it will not appear
217218
in the options set that is passed to the plugin.
@@ -229,7 +230,6 @@ Here's an example option set, as sent in response to `getmanifest`
229230
{
230231
"name": "run-hot",
231232
"type": "flag",
232-
"default": None, // defaults to false
233233
"description": "If set, overclocks plugin"
234234
},
235235
{

lightningd/plugin.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,8 +973,13 @@ static const char *plugin_opt_add(struct plugin *plugin, const char *buffer,
973973
"%s type \"%s\" cannot have multi",
974974
popt->name, popt->type);
975975
/* We default flags to false, the default token is ignored */
976-
if (json_tok_streq(buffer, typetok, "flag"))
976+
if (json_tok_streq(buffer, typetok, "flag") && defaulttok) {
977+
if (!deprecated_apis) {
978+
return tal_fmt(plugin, "%s type flag cannot have default",
979+
popt->name);
980+
}
977981
defaulttok = NULL;
982+
}
978983
} else {
979984
return tal_fmt(plugin,
980985
"Only \"string\", \"int\", \"bool\", and \"flag\" options are supported");

0 commit comments

Comments
 (0)