mirror of
https://github.com/ElementsProject/lightning.git
synced 2026-08-16 13:00:32 +02:00
libplugin: add helpers for multi-string options
Changelog-None Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
This commit is contained in:
parent
b1d77a62d3
commit
03e5d22a95
3 changed files with 24 additions and 21 deletions
|
|
@ -1688,6 +1688,14 @@ char *charp_option(struct command *cmd, const char *arg, bool check_only, char *
|
|||
return NULL;
|
||||
}
|
||||
|
||||
char *multi_string_option(struct command *cmd, const char *arg, bool check_only,
|
||||
const char ***arr)
|
||||
{
|
||||
if (!check_only)
|
||||
tal_arr_expand(arr, tal_strdup(*arr, arg));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool u64_jsonfmt(struct command *cmd, struct json_stream *js, const char *fieldname, u64 *i)
|
||||
{
|
||||
json_add_u64(js, fieldname, *i);
|
||||
|
|
@ -1720,6 +1728,16 @@ bool charp_jsonfmt(struct command *cmd, struct json_stream *js, const char *fiel
|
|||
return true;
|
||||
}
|
||||
|
||||
bool string_array_jsonfmt(struct command *cmd, struct json_stream *js,
|
||||
const char *fieldname, const char ***arr)
|
||||
{
|
||||
json_array_start(js, fieldname);
|
||||
for (size_t i = 0; i < tal_count(*arr); i++)
|
||||
json_add_string(js, NULL, (*arr)[i]);
|
||||
json_array_end(js);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool flag_jsonfmt(struct command *cmd, struct json_stream *js, const char *fieldname, bool *i)
|
||||
{
|
||||
/* Don't print if the default (false) */
|
||||
|
|
|
|||
|
|
@ -638,6 +638,8 @@ char *u32_option(struct command *cmd, const char *arg, bool check_only, u32 *i);
|
|||
char *u16_option(struct command *cmd, const char *arg, bool check_only, u16 *i);
|
||||
char *bool_option(struct command *cmd, const char *arg, bool check_only, bool *i);
|
||||
char *charp_option(struct command *cmd, const char *arg, bool check_only, char **p);
|
||||
char *multi_string_option(struct command *cmd, const char *arg, bool check_only,
|
||||
const char ***arr);
|
||||
char *flag_option(struct command *cmd, const char *arg, bool check_only, bool *i);
|
||||
|
||||
bool u64_jsonfmt(struct command *cmd, struct json_stream *js, const char *fieldname,
|
||||
|
|
@ -650,6 +652,8 @@ bool bool_jsonfmt(struct command *cmd, struct json_stream *js, const char *field
|
|||
bool *i);
|
||||
bool charp_jsonfmt(struct command *cmd, struct json_stream *js, const char *fieldname,
|
||||
char **p);
|
||||
bool string_array_jsonfmt(struct command *cmd, struct json_stream *js,
|
||||
const char *fieldname, const char ***arr);
|
||||
|
||||
/* Usually equivalent to NULL, since flag must default to false be useful! */
|
||||
bool flag_jsonfmt(struct command *cmd, struct json_stream *js, const char *fieldname,
|
||||
|
|
|
|||
|
|
@ -372,25 +372,6 @@ static const struct plugin_notification notifs[] = { {
|
|||
}
|
||||
};
|
||||
|
||||
static char *set_multi_string_option(struct command *cmd,
|
||||
const char *arg,
|
||||
bool check_only,
|
||||
const char ***arr)
|
||||
{
|
||||
if (!check_only)
|
||||
tal_arr_expand(arr, tal_strdup(*arr, arg));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool multi_string_jsonfmt(struct command *cmd, struct json_stream *js, const char *fieldname, const char ***arr)
|
||||
{
|
||||
json_array_start(js, fieldname);
|
||||
for (size_t i = 0; i < tal_count(*arr); i++)
|
||||
json_add_string(js, NULL, (*arr)[i]);
|
||||
json_array_end(js);
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
setup_locale();
|
||||
|
|
@ -436,8 +417,8 @@ int main(int argc, char *argv[])
|
|||
plugin_option_multi("multiopt",
|
||||
"string",
|
||||
"Set me multiple times!",
|
||||
set_multi_string_option,
|
||||
multi_string_jsonfmt,
|
||||
multi_string_option,
|
||||
string_array_jsonfmt,
|
||||
&tlp->strarr),
|
||||
NULL);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue