Global: refactor code of -h <module>-format

This commit is contained in:
李通洲
2024-12-11 10:47:02 +08:00
parent e45ff546ed
commit 9a36d63d18
78 changed files with 1454 additions and 1872 deletions
+23 -29
View File
@@ -5,8 +5,6 @@
#include "modules/version/version.h"
#include "util/stringUtils.h"
#define FF_VERSION_NUM_FORMAT_ARGS 10
void ffPrintVersion(FFVersionOptions* options)
{
FFVersionResult* result = &ffVersionResult;
@@ -31,7 +29,7 @@ void ffPrintVersion(FFVersionOptions* options)
}
const char* buildType = result->debugMode ? "debug" : "release";
FF_PRINT_FORMAT_CHECKED(FF_VERSION_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_VERSION_NUM_FORMAT_ARGS, ((FFformatarg[]){
FF_PRINT_FORMAT_CHECKED(FF_VERSION_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]){
FF_FORMAT_ARG(result->projectName, "project-name"),
FF_FORMAT_ARG(result->version, "version"),
FF_FORMAT_ARG(result->versionTweak, "version-tweak"),
@@ -113,35 +111,31 @@ void ffGenerateVersionJsonResult(FF_MAYBE_UNUSED FFVersionOptions* options, yyjs
}
}
void ffPrintVersionHelpFormat(void)
{
FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_VERSION_MODULE_NAME, "{1} {2}{3} ({5})", FF_VERSION_NUM_FORMAT_ARGS, ((const char* []) {
"Project name - name",
"Version - version",
"Version tweak - version-tweak",
"Build type (debug or release) - build-type",
"System name - sysname",
"Architecture - arch",
"CMake build type when compiling (Debug, Release, RelWithDebInfo, MinSizeRel) - cmake-built-type",
"Date time when compiling - compile-time",
"Compiler used when compiling - compiler",
"Libc used when compiling - libc",
}));
}
static FFModuleBaseInfo ffModuleInfo = {
.name = FF_VERSION_MODULE_NAME,
.description = "Print Fastfetch version",
.parseCommandOptions = (void*) ffParseVersionCommandOptions,
.parseJsonObject = (void*) ffParseVersionJsonObject,
.printModule = (void*) ffPrintVersion,
.generateJsonResult = (void*) ffGenerateVersionJsonResult,
.generateJsonConfig = (void*) ffGenerateVersionJsonConfig,
.formatArgs = FF_FORMAT_ARG_LIST(((FFModuleFormatArg[]) {
{"Project name", "name"},
{"Version", "version"},
{"Version tweak", "version-tweak"},
{"Build type (debug or release)", "build-type"},
{"System name", "sysname"},
{"Architecture", "arch"},
{"CMake build type when compiling (Debug, Release, RelWithDebInfo, MinSizeRel)", "cmake-built-type"},
{"Date time when compiling", "compile-time"},
{"Compiler used when compiling", "compiler"},
{"Libc used when compiling", "libc"},
}))
};
void ffInitVersionOptions(FFVersionOptions* options)
{
ffOptionInitModuleBaseInfo(
&options->moduleInfo,
FF_VERSION_MODULE_NAME,
"Print Fastfetch version",
ffParseVersionCommandOptions,
ffParseVersionJsonObject,
ffPrintVersion,
ffGenerateVersionJsonResult,
ffPrintVersionHelpFormat,
ffGenerateVersionJsonConfig
);
options->moduleInfo = ffModuleInfo;
ffOptionInitModuleArg(&options->moduleArgs, "");
}