MCPcopy Create free account
hub / github.com/ElementsProject/lightning / plugin_opt_add

Function plugin_opt_add

lightningd/plugin.c:906–994  ·  view source on GitHub ↗

Add a single plugin option to the plugin as well as registering it with the * command line options. */

Source from the content-addressed store, hash-verified

904/* Add a single plugin option to the plugin as well as registering it with the
905 * command line options. */
906static const char *plugin_opt_add(struct plugin *plugin, const char *buffer,
907 const jsmntok_t *opt)
908{
909 const jsmntok_t *nametok, *typetok, *defaulttok, *desctok, *deptok, *multitok;
910 struct plugin_opt *popt;
911 nametok = json_get_member(buffer, opt, "name");
912 typetok = json_get_member(buffer, opt, "type");
913 desctok = json_get_member(buffer, opt, "description");
914 defaulttok = json_get_member(buffer, opt, "default");
915 deptok = json_get_member(buffer, opt, "deprecated");
916 multitok = json_get_member(buffer, opt, "multi");
917
918 if (!typetok || !nametok || !desctok) {
919 return tal_fmt(plugin,
920 "An option is missing either \"name\", \"description\" or \"type\"");
921 }
922
923 popt = tal(plugin, struct plugin_opt);
924 popt->values = tal_arr(popt, struct plugin_opt_value *, 0);
925
926 popt->name = tal_fmt(popt, "--%.*s", nametok->end - nametok->start,
927 buffer + nametok->start);
928
929 /* an "|" alias could circumvent the unique-option-name check */
930 if (strchr(popt->name, '|'))
931 return tal_fmt(plugin, "Option \"name\" may not contain '|'");
932
933 popt->description = json_strdup(popt, buffer, desctok);
934 if (deptok) {
935 if (!json_to_bool(buffer, deptok, &popt->deprecated))
936 return tal_fmt(plugin,
937 "%s: invalid \"deprecated\" field %.*s",
938 popt->name,
939 deptok->end - deptok->start,
940 buffer + deptok->start);
941 } else
942 popt->deprecated = false;
943
944 if (multitok) {
945 if (!json_to_bool(buffer, multitok, &popt->multi))
946 return tal_fmt(plugin,
947 "%s: invalid \"multi\" field %.*s",
948 popt->name,
949 multitok->end - multitok->start,
950 buffer + multitok->start);
951 } else
952 popt->multi = false;
953
954 popt->def = NULL;
955 if (json_tok_streq(buffer, typetok, "string")) {
956 popt->type = "string";
957 } else if (json_tok_streq(buffer, typetok, "int")) {
958 popt->type = "int";
959 } else if (json_tok_streq(buffer, typetok, "bool")
960 || json_tok_streq(buffer, typetok, "flag")) {
961 popt->type = json_strdup(popt, buffer, typetok);
962 if (popt->multi)
963 return tal_fmt(plugin,

Callers 1

plugin_opts_addFunction · 0.85

Calls 10

json_tok_is_nullFunction · 0.85
plugin_opt_registerFunction · 0.85
plugin_opt_valueFunction · 0.70
fatalFunction · 0.70
json_get_memberFunction · 0.50
json_strdupFunction · 0.50
json_to_boolFunction · 0.50
json_tok_streqFunction · 0.50
json_tok_full_lenFunction · 0.50
json_tok_fullFunction · 0.50

Tested by

no test coverage detected