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
@@ -6,7 +6,6 @@
#include "modules/physicalmemory/physicalmemory.h"
#include "util/stringUtils.h"
#define FF_PHYSICALMEMORY_NUM_FORMAT_ARGS 11
#define FF_PHYSICALMEMORY_DISPLAY_NAME "Physical Memory"
void ffPrintPhysicalMemory(FFPhysicalMemoryOptions* options)
@@ -54,7 +53,7 @@ void ffPrintPhysicalMemory(FFPhysicalMemoryOptions* options)
}
else
{
FF_PRINT_FORMAT_CHECKED(FF_PHYSICALMEMORY_DISPLAY_NAME, (uint8_t) i, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_PHYSICALMEMORY_NUM_FORMAT_ARGS, ((FFformatarg[]) {
FF_PRINT_FORMAT_CHECKED(FF_PHYSICALMEMORY_DISPLAY_NAME, (uint8_t) i, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]) {
FF_FORMAT_ARG(device->size, "bytes"),
FF_FORMAT_ARG(prettySize, "size"),
FF_FORMAT_ARG(device->maxSpeed, "max-speed"),
@@ -154,36 +153,31 @@ void ffGeneratePhysicalMemoryJsonResult(FF_MAYBE_UNUSED FFPhysicalMemoryOptions*
}
}
void ffPrintPhysicalMemoryHelpFormat(void)
{
FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_PHYSICALMEMORY_MODULE_NAME, "{7} {5}-{3}: {2}, running at {4} MT/s", FF_PHYSICALMEMORY_NUM_FORMAT_ARGS, ((const char* []) {
"Size (in bytes) - bytes",
"Size formatted - size",
"Max speed (in MT/s) - max-speed",
"Running speed (in MT/s) - running-speed",
"Type (DDR4, DDR5, etc.) - type",
"Form factor (SODIMM, DIMM, etc.) - form-factor",
"Bank/Device Locator (BANK0/SIMM0, BANK0/SIMM1, etc.) - locator",
"Vendor - vendor",
"Serial number - serial",
"Part number - part-number",
"True if ECC enabled - is-ecc-enabled",
}));
}
static FFModuleBaseInfo ffModuleInfo = {
.name = FF_PHYSICALMEMORY_MODULE_NAME,
.description = "Print system physical memory devices",
.parseCommandOptions = (void*) ffParsePhysicalMemoryCommandOptions,
.parseJsonObject = (void*) ffParsePhysicalMemoryJsonObject,
.printModule = (void*) ffPrintPhysicalMemory,
.generateJsonConfig = (void*) ffGeneratePhysicalMemoryJsonConfig,
.formatArgs = FF_FORMAT_ARG_LIST(((FFModuleFormatArg[]) {
{"Size (in bytes)", "bytes"},
{"Size formatted", "size"},
{"Max speed (in MT/s)", "max-speed"},
{"Running speed (in MT/s)", "running-speed"},
{"Type (DDR4, DDR5, etc.)", "type"},
{"Form factor (SODIMM, DIMM, etc.)", "form-factor"},
{"Bank/Device Locator (BANK0/SIMM0, BANK0/SIMM1, etc.)", "locator"},
{"Vendor", "vendor"},
{"Serial number", "serial"},
{"Part number", "part-number"},
{"True if ECC enabled", "is-ecc-enabled"},
}))
};
void ffInitPhysicalMemoryOptions(FFPhysicalMemoryOptions* options)
{
ffOptionInitModuleBaseInfo(
&options->moduleInfo,
FF_PHYSICALMEMORY_MODULE_NAME,
"Print system physical memory devices",
ffParsePhysicalMemoryCommandOptions,
ffParsePhysicalMemoryJsonObject,
ffPrintPhysicalMemory,
ffGeneratePhysicalMemoryJsonResult,
ffPrintPhysicalMemoryHelpFormat,
ffGeneratePhysicalMemoryJsonConfig
);
options->moduleInfo = ffModuleInfo;
ffOptionInitModuleArg(&options->moduleArgs, "󰑭");
}