mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2025-02-20 11:43:27 +08:00
Fastfetch: add -h format-json
This commit is contained in:
parent
9a36d63d18
commit
ebfdeef25c
@ -16,6 +16,43 @@
|
|||||||
#include "util/windows/getline.h"
|
#include "util/windows/getline.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void printCommandFormatHelpJson(void)
|
||||||
|
{
|
||||||
|
yyjson_mut_doc* doc = yyjson_mut_doc_new(NULL);
|
||||||
|
yyjson_mut_val* root = yyjson_mut_obj(doc);
|
||||||
|
yyjson_mut_doc_set_root(doc, root);
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i <= 'Z' - 'A'; ++i)
|
||||||
|
{
|
||||||
|
for (FFModuleBaseInfo** modules = ffModuleInfos[i]; *modules; ++modules)
|
||||||
|
{
|
||||||
|
FFModuleBaseInfo* baseInfo = *modules;
|
||||||
|
if (!baseInfo->formatArgs.count) continue;
|
||||||
|
|
||||||
|
FF_STRBUF_AUTO_DESTROY type = ffStrbufCreateS(baseInfo->name);
|
||||||
|
ffStrbufLowerCase(&type);
|
||||||
|
ffStrbufAppendS(&type, "Format");
|
||||||
|
|
||||||
|
yyjson_mut_val* obj = yyjson_mut_obj(doc);
|
||||||
|
if (yyjson_mut_obj_add(root, yyjson_mut_strbuf(doc, &type), obj))
|
||||||
|
{
|
||||||
|
FF_STRBUF_AUTO_DESTROY content = ffStrbufCreateF("Output format of the module `%s`. See `-h format` for formatting syntax\n", baseInfo->name);
|
||||||
|
for (unsigned i = 0; i < baseInfo->formatArgs.count; i++)
|
||||||
|
{
|
||||||
|
const FFModuleFormatArg* arg = &baseInfo->formatArgs.args[i];
|
||||||
|
ffStrbufAppendF(&content, " %u. {%s}: %s\n", i + 1, arg->name, arg->desc);
|
||||||
|
}
|
||||||
|
ffStrbufTrimRight(&content, '\n');
|
||||||
|
yyjson_mut_obj_add_strbuf(doc, obj, "description", &content);
|
||||||
|
yyjson_mut_obj_add_str(doc, obj, "type", "string");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
yyjson_mut_write_fp(stdout, doc, YYJSON_WRITE_PRETTY, NULL, NULL);
|
||||||
|
putchar('\n');
|
||||||
|
yyjson_mut_doc_free(doc);
|
||||||
|
}
|
||||||
|
|
||||||
static void printCommandFormatHelp(const char* command)
|
static void printCommandFormatHelp(const char* command)
|
||||||
{
|
{
|
||||||
FF_STRBUF_AUTO_DESTROY type = ffStrbufCreateNS((uint32_t) (strlen(command) - strlen("-format")), command);
|
FF_STRBUF_AUTO_DESTROY type = ffStrbufCreateNS((uint32_t) (strlen(command) - strlen("-format")), command);
|
||||||
@ -265,6 +302,8 @@ static void printCommandHelp(const char* command)
|
|||||||
puts(FASTFETCH_DATATEXT_HELP_COLOR);
|
puts(FASTFETCH_DATATEXT_HELP_COLOR);
|
||||||
else if(ffStrEqualsIgnCase(command, "format"))
|
else if(ffStrEqualsIgnCase(command, "format"))
|
||||||
puts(FASTFETCH_DATATEXT_HELP_FORMAT);
|
puts(FASTFETCH_DATATEXT_HELP_FORMAT);
|
||||||
|
else if(ffStrEqualsIgnCase(command, "format-json"))
|
||||||
|
printCommandFormatHelpJson();
|
||||||
else if(ffCharIsEnglishAlphabet(command[0]) && ffStrEndsWithIgnCase(command, "-format")) // <module>-format
|
else if(ffCharIsEnglishAlphabet(command[0]) && ffStrEndsWithIgnCase(command, "-format")) // <module>-format
|
||||||
printCommandFormatHelp(command);
|
printCommandFormatHelp(command);
|
||||||
else if(!printSpecificCommandHelp(command))
|
else if(!printSpecificCommandHelp(command))
|
||||||
|
@ -218,7 +218,7 @@ void ffGenerateBtrfsJsonResult(FF_MAYBE_UNUSED FFBtrfsOptions* options, yyjson_m
|
|||||||
|
|
||||||
static FFModuleBaseInfo ffModuleInfo = {
|
static FFModuleBaseInfo ffModuleInfo = {
|
||||||
.name = FF_BTRFS_MODULE_NAME,
|
.name = FF_BTRFS_MODULE_NAME,
|
||||||
.description = "Print BTRFS volumes",
|
.description = "Print Linux BTRFS volumes",
|
||||||
.parseCommandOptions = (void*) ffParseBtrfsCommandOptions,
|
.parseCommandOptions = (void*) ffParseBtrfsCommandOptions,
|
||||||
.parseJsonObject = (void*) ffParseBtrfsJsonObject,
|
.parseJsonObject = (void*) ffParseBtrfsJsonObject,
|
||||||
.printModule = (void*) ffPrintBtrfs,
|
.printModule = (void*) ffPrintBtrfs,
|
||||||
|
@ -104,7 +104,7 @@ void ffGenerateFontJsonResult(FF_MAYBE_UNUSED FFFontOptions* options, yyjson_mut
|
|||||||
|
|
||||||
static FFModuleBaseInfo ffModuleInfo = {
|
static FFModuleBaseInfo ffModuleInfo = {
|
||||||
.name = FF_FONT_MODULE_NAME,
|
.name = FF_FONT_MODULE_NAME,
|
||||||
.description = "Print system font name",
|
.description = "Print system font names",
|
||||||
.parseCommandOptions = (void*) ffParseFontCommandOptions,
|
.parseCommandOptions = (void*) ffParseFontCommandOptions,
|
||||||
.parseJsonObject = (void*) ffParseFontJsonObject,
|
.parseJsonObject = (void*) ffParseFontJsonObject,
|
||||||
.printModule = (void*) ffPrintFont,
|
.printModule = (void*) ffPrintFont,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user