Skip to content

Commit ebfdeef

Browse files
committed
Fastfetch: add -h format-json
1 parent 9a36d63 commit ebfdeef

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

src/fastfetch.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,43 @@
1616
#include "util/windows/getline.h"
1717
#endif
1818

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+
1956
static void printCommandFormatHelp(const char* command)
2057
{
2158
FF_STRBUF_AUTO_DESTROY type = ffStrbufCreateNS((uint32_t) (strlen(command) - strlen("-format")), command);
@@ -265,6 +302,8 @@ static void printCommandHelp(const char* command)
265302
puts(FASTFETCH_DATATEXT_HELP_COLOR);
266303
else if(ffStrEqualsIgnCase(command, "format"))
267304
puts(FASTFETCH_DATATEXT_HELP_FORMAT);
305+
else if(ffStrEqualsIgnCase(command, "format-json"))
306+
printCommandFormatHelpJson();
268307
else if(ffCharIsEnglishAlphabet(command[0]) && ffStrEndsWithIgnCase(command, "-format")) // <module>-format
269308
printCommandFormatHelp(command);
270309
else if(!printSpecificCommandHelp(command))

src/modules/btrfs/btrfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ void ffGenerateBtrfsJsonResult(FF_MAYBE_UNUSED FFBtrfsOptions* options, yyjson_m
218218

219219
static FFModuleBaseInfo ffModuleInfo = {
220220
.name = FF_BTRFS_MODULE_NAME,
221-
.description = "Print BTRFS volumes",
221+
.description = "Print Linux BTRFS volumes",
222222
.parseCommandOptions = (void*) ffParseBtrfsCommandOptions,
223223
.parseJsonObject = (void*) ffParseBtrfsJsonObject,
224224
.printModule = (void*) ffPrintBtrfs,

src/modules/font/font.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void ffGenerateFontJsonResult(FF_MAYBE_UNUSED FFFontOptions* options, yyjson_mut
104104

105105
static FFModuleBaseInfo ffModuleInfo = {
106106
.name = FF_FONT_MODULE_NAME,
107-
.description = "Print system font name",
107+
.description = "Print system font names",
108108
.parseCommandOptions = (void*) ffParseFontCommandOptions,
109109
.parseJsonObject = (void*) ffParseFontJsonObject,
110110
.printModule = (void*) ffPrintFont,

0 commit comments

Comments
 (0)