|
16 | 16 | #include "util/windows/getline.h" |
17 | 17 | #endif |
18 | 18 |
|
| 19 | +static void printCommandFormatHelpJson(void) |
| 20 | +{ |
| 21 | + yyjson_mut_doc* doc = yyjson_mut_doc_new(NULL); |
| 22 | + yyjson_mut_val* root = yyjson_mut_obj(doc); |
| 23 | + yyjson_mut_doc_set_root(doc, root); |
| 24 | + |
| 25 | + for (uint32_t i = 0; i <= 'Z' - 'A'; ++i) |
| 26 | + { |
| 27 | + for (FFModuleBaseInfo** modules = ffModuleInfos[i]; *modules; ++modules) |
| 28 | + { |
| 29 | + FFModuleBaseInfo* baseInfo = *modules; |
| 30 | + if (!baseInfo->formatArgs.count) continue; |
| 31 | + |
| 32 | + FF_STRBUF_AUTO_DESTROY type = ffStrbufCreateS(baseInfo->name); |
| 33 | + ffStrbufLowerCase(&type); |
| 34 | + ffStrbufAppendS(&type, "Format"); |
| 35 | + |
| 36 | + yyjson_mut_val* obj = yyjson_mut_obj(doc); |
| 37 | + if (yyjson_mut_obj_add(root, yyjson_mut_strbuf(doc, &type), obj)) |
| 38 | + { |
| 39 | + FF_STRBUF_AUTO_DESTROY content = ffStrbufCreateF("Output format of the module `%s`. See `-h format` for formatting syntax\n", baseInfo->name); |
| 40 | + for (unsigned i = 0; i < baseInfo->formatArgs.count; i++) |
| 41 | + { |
| 42 | + const FFModuleFormatArg* arg = &baseInfo->formatArgs.args[i]; |
| 43 | + ffStrbufAppendF(&content, " %u. {%s}: %s\n", i + 1, arg->name, arg->desc); |
| 44 | + } |
| 45 | + ffStrbufTrimRight(&content, '\n'); |
| 46 | + yyjson_mut_obj_add_strbuf(doc, obj, "description", &content); |
| 47 | + yyjson_mut_obj_add_str(doc, obj, "type", "string"); |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + yyjson_mut_write_fp(stdout, doc, YYJSON_WRITE_PRETTY, NULL, NULL); |
| 52 | + putchar('\n'); |
| 53 | + yyjson_mut_doc_free(doc); |
| 54 | +} |
| 55 | + |
19 | 56 | static void printCommandFormatHelp(const char* command) |
20 | 57 | { |
21 | 58 | FF_STRBUF_AUTO_DESTROY type = ffStrbufCreateNS((uint32_t) (strlen(command) - strlen("-format")), command); |
@@ -265,6 +302,8 @@ static void printCommandHelp(const char* command) |
265 | 302 | puts(FASTFETCH_DATATEXT_HELP_COLOR); |
266 | 303 | else if(ffStrEqualsIgnCase(command, "format")) |
267 | 304 | puts(FASTFETCH_DATATEXT_HELP_FORMAT); |
| 305 | + else if(ffStrEqualsIgnCase(command, "format-json")) |
| 306 | + printCommandFormatHelpJson(); |
268 | 307 | else if(ffCharIsEnglishAlphabet(command[0]) && ffStrEndsWithIgnCase(command, "-format")) // <module>-format |
269 | 308 | printCommandFormatHelp(command); |
270 | 309 | else if(!printSpecificCommandHelp(command)) |
|
0 commit comments