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

Function human_help

cli/lightning-cli.c:176–220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174}
175
176static void human_help(char *buffer, const jsmntok_t *result)
177{
178 unsigned int i;
179 /* `curr` is used as a temporary token */
180 const jsmntok_t *curr;
181 const char *prev_cat;
182 /* Contains all commands objects, which have the following structure :
183 * {
184 * "command": "The command name and usage",
185 * "category": "The command category",
186 * "description": "The command's description",
187 * "verbose": "The command's detailed description"
188 * }
189 */
190 const jsmntok_t * help_array = json_get_member(buffer, result, "help");
191 const jsmntok_t **help = tal_arr(NULL, const jsmntok_t *,
192 help_array->size);
193
194 /* Populate an array for easy sorting with asort */
195 json_for_each_arr(i, curr, help_array)
196 help[i] = curr;
197
198 asort(help, tal_count(help), compare_help, buffer);
199
200 prev_cat = "";
201 for (i = 0; i < tal_count(help); i++) {
202 const jsmntok_t *category, *command, *desc;
203
204 category = json_get_member(buffer, help[i], "category");
205 if (category && !json_tok_streq(buffer, category, prev_cat)) {
206 prev_cat = json_strdup(help, buffer, category);
207 printf("=== %s ===\n\n", prev_cat);
208 }
209
210 command = json_get_member(buffer, help[i], "command");
211 desc = json_get_member(buffer, help[i], "description");
212 printf("%.*s\n",
213 command->end - command->start, buffer + command->start);
214 printf(" %.*s\n\n",
215 desc->end - desc->start, buffer + desc->start);
216 }
217 tal_free(help);
218
219 printf("---\nrun `lightning-cli help <command>` for more information on a specific command\n");
220}
221
222enum format {
223 JSON,

Callers 1

mainFunction · 0.85

Calls 4

tal_freeFunction · 0.85
json_get_memberFunction · 0.50
json_tok_streqFunction · 0.50
json_strdupFunction · 0.50

Tested by

no test coverage detected