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 <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2023-06-02 12:06:04 +09:30
parent b9270c564a
commit 0df97547dd
3 changed files with 10 additions and 5 deletions

View file

@ -912,7 +912,7 @@ class Plugin(object):
m["long_description"] = method.long_desc
manifest = {
'options': list(self.options.values()),
'options': list({k: v for k, v in d.items() if v is not None} for d in self.options.values()),
'rpcmethods': methods,
'subscriptions': list(self.subscriptions.keys()),
'hooks': hooks,

View file

@ -207,11 +207,12 @@ There are currently four supported option 'types':
- string: a string
- bool: a boolean
- int: parsed as a signed integer (64-bit)
- flag: no-arg flag option. Is boolean under the hood. Defaults to false.
- flag: no-arg flag option. Presented as `true` if config specifies it.
In addition, string and int types can specify `"multi": true` to indicate
they can be specified multiple times. These will always be represented in
`init` as a (possibly empty) JSON array.
`init` as a (possibly empty) JSON array. "multi" flag types do not make
sense.
Nota bene: if a `flag` type option is not set, it will not appear
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`
{
"name": "run-hot",
"type": "flag",
"default": None, // defaults to false
"description": "If set, overclocks plugin"
},
{

View file

@ -973,8 +973,13 @@ static const char *plugin_opt_add(struct plugin *plugin, const char *buffer,
"%s type \"%s\" cannot have multi",
popt->name, popt->type);
/* We default flags to false, the default token is ignored */
if (json_tok_streq(buffer, typetok, "flag"))
if (json_tok_streq(buffer, typetok, "flag") && defaulttok) {
if (!deprecated_apis) {
return tal_fmt(plugin, "%s type flag cannot have default",
popt->name);
}
defaulttok = NULL;
}
} else {
return tal_fmt(plugin,
"Only \"string\", \"int\", \"bool\", and \"flag\" options are supported");