diff --git a/plugins/libplugin.c b/plugins/libplugin.c index b39058d46..db2e53fb7 100644 --- a/plugins/libplugin.c +++ b/plugins/libplugin.c @@ -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) */ diff --git a/plugins/libplugin.h b/plugins/libplugin.h index bddba28f7..3e435f65e 100644 --- a/plugins/libplugin.h +++ b/plugins/libplugin.h @@ -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, diff --git a/tests/plugins/test_libplugin.c b/tests/plugins/test_libplugin.c index a89b61649..907d5c4b4 100644 --- a/tests/plugins/test_libplugin.c +++ b/tests/plugins/test_libplugin.c @@ -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); }