mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-12 10:22:12 +02:00
Chassis: add Json printing support
This commit is contained in:
@@ -52,7 +52,7 @@ exit:
|
||||
|
||||
void ffInitChassisOptions(FFChassisOptions* options)
|
||||
{
|
||||
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CHASSIS_MODULE_NAME, ffParseChassisCommandOptions, ffParseChassisJsonObject, ffPrintChassis, NULL);
|
||||
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CHASSIS_MODULE_NAME, ffParseChassisCommandOptions, ffParseChassisJsonObject, ffPrintChassis, ffGenerateChassisJson);
|
||||
ffOptionInitModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
@@ -87,3 +87,36 @@ void ffParseChassisJsonObject(FFChassisOptions* options, yyjson_val* module)
|
||||
ffPrintError(FF_CHASSIS_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
void ffGenerateChassisJson(FF_MAYBE_UNUSED FFChassisOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
{
|
||||
FFChassisResult result;
|
||||
ffStrbufInit(&result.type);
|
||||
ffStrbufInit(&result.vendor);
|
||||
ffStrbufInit(&result.version);
|
||||
|
||||
const char* error = ffDetectChassis(&result);
|
||||
|
||||
if (error)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", error);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if(result.type.length == 0)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", "chassis_type is not set by O.E.M.");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
yyjson_mut_val* obj = yyjson_mut_obj(doc);
|
||||
yyjson_mut_obj_add_val(doc, module, "result", obj);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "type", &result.type);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "vendor", &result.vendor);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "version", &result.version);
|
||||
|
||||
exit:
|
||||
ffStrbufDestroy(&result.type);
|
||||
ffStrbufDestroy(&result.vendor);
|
||||
ffStrbufDestroy(&result.version);
|
||||
}
|
||||
|
||||
@@ -9,3 +9,4 @@ void ffInitChassisOptions(FFChassisOptions* options);
|
||||
bool ffParseChassisCommandOptions(FFChassisOptions* options, const char* key, const char* value);
|
||||
void ffDestroyChassisOptions(FFChassisOptions* options);
|
||||
void ffParseChassisJsonObject(FFChassisOptions* options, yyjson_val* module);
|
||||
void ffGenerateChassisJson(FFChassisOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module);
|
||||
|
||||
Reference in New Issue
Block a user