| 174 | } |
| 175 | |
| 176 | static 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 | /* Contains all commands objects, which have the following structure : |
| 182 | * { |
| 183 | * "command": "The command name and usage" |
| 184 | * } |
| 185 | */ |
| 186 | const jsmntok_t * help_array = json_get_member(buffer, result, "help"); |
| 187 | const jsmntok_t **help = tal_arr(NULL, const jsmntok_t *, |
| 188 | help_array->size); |
| 189 | |
| 190 | /* Populate an array for easy sorting with asort */ |
| 191 | json_for_each_arr(i, curr, help_array) |
| 192 | help[i] = curr; |
| 193 | |
| 194 | asort(help, tal_count(help), compare_help, buffer); |
| 195 | |
| 196 | for (i = 0; i < tal_count(help); i++) { |
| 197 | const jsmntok_t *command; |
| 198 | command = json_get_member(buffer, help[i], "command"); |
| 199 | human_readable(buffer, command, '\n'); |
| 200 | printf("\n"); |
| 201 | } |
| 202 | tal_free(help); |
| 203 | |
| 204 | printf("---\nrun `lightning-cli help <command>` for more information on a specific command\n"); |
| 205 | } |
| 206 | |
| 207 | enum format { |
| 208 | JSON, |
no test coverage detected