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
+18 -24
View File
@@ -5,8 +5,6 @@
#include "modules/editor/editor.h"
#include "util/stringUtils.h"
#define FF_EDITOR_NUM_FORMAT_ARGS 5
void ffPrintEditor(FFEditorOptions* options)
{
FFEditorResult result = {
@@ -41,7 +39,7 @@ void ffPrintEditor(FFEditorOptions* options)
}
else
{
FF_PRINT_FORMAT_CHECKED(FF_EDITOR_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_EDITOR_NUM_FORMAT_ARGS, ((FFformatarg[]){
FF_PRINT_FORMAT_CHECKED(FF_EDITOR_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]){
FF_FORMAT_ARG(result.type, "type"),
FF_FORMAT_ARG(result.name, "name"),
FF_FORMAT_ARG(result.exe, "exe-name"),
@@ -120,30 +118,26 @@ void ffGenerateEditorJsonResult(FF_MAYBE_UNUSED FFEditorOptions* options, yyjson
ffStrbufDestroy(&result.version);
}
void ffPrintEditorHelpFormat(void)
{
FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_EDITOR_MODULE_NAME, "{2} ({4})", FF_EDITOR_NUM_FORMAT_ARGS, ((const char* []) {
"Type (Visual / Editor) - type",
"Name - name",
"Exe name of real path - exe-name",
"Full path of real path - full-path",
"Version - version",
}));
}
static FFModuleBaseInfo ffModuleInfo = {
.name = FF_EDITOR_MODULE_NAME,
.description = "Print information of the default editor ($VISUAL or $EDITOR)",
.parseCommandOptions = (void*) ffParseEditorCommandOptions,
.parseJsonObject = (void*) ffParseEditorJsonObject,
.printModule = (void*) ffPrintEditor,
.generateJsonResult = (void*) ffGenerateEditorJsonResult,
.generateJsonConfig = (void*) ffGenerateEditorJsonConfig,
.formatArgs = FF_FORMAT_ARG_LIST(((FFModuleFormatArg[]) {
{"Type (Visual / Editor)", "type"},
{"Name", "name"},
{"Exe name of real path", "exe-name"},
{"Full path of real path", "full-path"},
{"Version", "version"},
}))
};
void ffInitEditorOptions(FFEditorOptions* options)
{
ffOptionInitModuleBaseInfo(
&options->moduleInfo,
FF_EDITOR_MODULE_NAME,
"Print information of the default editor ($VISUAL or $EDITOR)",
ffParseEditorCommandOptions,
ffParseEditorJsonObject,
ffPrintEditor,
ffGenerateEditorJsonResult,
ffPrintEditorHelpFormat,
ffGenerateEditorJsonConfig
);
options->moduleInfo = ffModuleInfo;
ffOptionInitModuleArg(&options->moduleArgs, "󱞎");
}