mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2025-02-20 11:43:27 +08:00
Global: tidy json result formats
This commit is contained in:
parent
1011e21ba8
commit
217f98a36c
@ -170,8 +170,5 @@ const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results)
|
||||
ffStrbufSubstrBefore(&baseDir, baseDirLength);
|
||||
}
|
||||
|
||||
if(results->length == 0)
|
||||
return "\"/sys/class/power_supply/\" doesn't contain any battery folder";
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -84,23 +84,28 @@ void ffPrintBattery(FFBatteryOptions* options)
|
||||
if (error)
|
||||
{
|
||||
ffPrintError(FF_BATTERY_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
|
||||
return;
|
||||
}
|
||||
else
|
||||
if(results.length == 0)
|
||||
{
|
||||
for(uint8_t i = 0; i < (uint8_t) results.length; i++)
|
||||
{
|
||||
FFBatteryResult* result = ffListGet(&results, i);
|
||||
printBattery(options, result, i);
|
||||
ffPrintError(FF_BATTERY_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", "No batteries found");
|
||||
return;
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&result->manufacturer);
|
||||
ffStrbufDestroy(&result->modelName);
|
||||
ffStrbufDestroy(&result->technology);
|
||||
ffStrbufDestroy(&result->status);
|
||||
ffStrbufDestroy(&result->serial);
|
||||
ffStrbufDestroy(&result->manufactureDate);
|
||||
}
|
||||
if(results.length == 0)
|
||||
ffPrintError(FF_BATTERY_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No batteries found");
|
||||
for(uint32_t i = 0; i < results.length; i++)
|
||||
{
|
||||
FFBatteryResult* result = ffListGet(&results, i);
|
||||
printBattery(options, result, (uint8_t) i);
|
||||
}
|
||||
|
||||
FF_LIST_FOR_EACH(FFBatteryResult, result, results)
|
||||
{
|
||||
ffStrbufDestroy(&result->manufacturer);
|
||||
ffStrbufDestroy(&result->modelName);
|
||||
ffStrbufDestroy(&result->technology);
|
||||
ffStrbufDestroy(&result->status);
|
||||
ffStrbufDestroy(&result->serial);
|
||||
ffStrbufDestroy(&result->manufactureDate);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,19 +150,17 @@ void ffGenerateBluetoothJsonResult(FF_MAYBE_UNUSED FFBluetoothOptions* options,
|
||||
yyjson_mut_obj_add_str(doc, module, "error", error);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
|
||||
|
||||
FF_LIST_FOR_EACH(FFBluetoothResult, item, results)
|
||||
{
|
||||
yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "address", &item->address);
|
||||
yyjson_mut_obj_add_uint(doc, obj, "battery", item->battery);
|
||||
yyjson_mut_obj_add_bool(doc, obj, "connected", item->connected);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "name", &item->name);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "type", &item->type);
|
||||
}
|
||||
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
|
||||
|
||||
FF_LIST_FOR_EACH(FFBluetoothResult, item, results)
|
||||
{
|
||||
yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "address", &item->address);
|
||||
yyjson_mut_obj_add_uint(doc, obj, "battery", item->battery);
|
||||
yyjson_mut_obj_add_bool(doc, obj, "connected", item->connected);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "name", &item->name);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "type", &item->type);
|
||||
}
|
||||
|
||||
FF_LIST_FOR_EACH(FFBluetoothResult, device, results)
|
||||
|
@ -154,12 +154,6 @@ void ffGenerateBrightnessJsonResult(FF_MAYBE_UNUSED FFBrightnessOptions* options
|
||||
return;
|
||||
}
|
||||
|
||||
if(result.length == 0)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", "No result is detected.");
|
||||
return;
|
||||
}
|
||||
|
||||
yyjson_mut_val* arr = yyjson_mut_arr(doc);
|
||||
yyjson_mut_obj_add_val(doc, module, "result", arr);
|
||||
|
||||
|
@ -152,7 +152,7 @@ void ffGenerateDateTimeJsonConfig(FFDateTimeOptions* options, yyjson_mut_doc* do
|
||||
|
||||
void ffGenerateDateTimeJsonResult(FF_MAYBE_UNUSED FFDateTimeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
{
|
||||
yyjson_mut_obj_add_uint(doc, module, "result", ffTimeGetNow());
|
||||
yyjson_mut_obj_add_strcpy(doc, module, "result", ffTimeToFullStr(ffTimeGetNow()));
|
||||
}
|
||||
|
||||
void ffPrintDateTimeHelpFormat(void)
|
||||
|
@ -279,6 +279,7 @@ void ffGenerateDisplayJsonResult(FF_MAYBE_UNUSED FFDisplayOptions* options, yyjs
|
||||
yyjson_mut_obj_add_str(doc, module, "error", "Couldn't detect display");
|
||||
return;
|
||||
}
|
||||
|
||||
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
|
||||
FF_LIST_FOR_EACH(FFDisplayResult, item, dsResult->displays)
|
||||
{
|
||||
|
@ -118,12 +118,6 @@ void ffGenerateGamepadJsonResult(FF_MAYBE_UNUSED FFGamepadOptions* options, yyjs
|
||||
return;
|
||||
}
|
||||
|
||||
if(!result.length)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", "No devices detected");
|
||||
return;
|
||||
}
|
||||
|
||||
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
|
||||
FF_LIST_FOR_EACH(FFGamepadDevice, device, result)
|
||||
{
|
||||
|
@ -334,13 +334,7 @@ void ffGenerateLocalIpJsonResult(FF_MAYBE_UNUSED FFLocalIpOptions* options, yyjs
|
||||
if(error)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", error);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if(results.length == 0)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", "Failed to detect any IPs");
|
||||
goto exit;
|
||||
return;
|
||||
}
|
||||
|
||||
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
|
||||
@ -354,7 +348,6 @@ void ffGenerateLocalIpJsonResult(FF_MAYBE_UNUSED FFLocalIpOptions* options, yyjs
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "name", &ip->name);
|
||||
}
|
||||
|
||||
exit:
|
||||
FF_LIST_FOR_EACH(FFLocalIpResult, ip, results)
|
||||
{
|
||||
ffStrbufDestroy(&ip->name);
|
||||
|
@ -101,24 +101,28 @@ void ffGeneratePowerAdapterJsonResult(FF_MAYBE_UNUSED FFPowerAdapterOptions* opt
|
||||
if (error)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", error);
|
||||
return;
|
||||
}
|
||||
else if(results.length == 0)
|
||||
|
||||
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
|
||||
FF_LIST_FOR_EACH(FFPowerAdapterResult, item, results)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", "No power adapters found");
|
||||
yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "description", &item->description);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "manufacturer", &item->manufacturer);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "modelName", &item->modelName);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "name", &item->name);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "serial", &item->serial);
|
||||
yyjson_mut_obj_add_int(doc, obj, "watts", item->watts);
|
||||
}
|
||||
else
|
||||
|
||||
FF_LIST_FOR_EACH(FFPowerAdapterResult, item, results)
|
||||
{
|
||||
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
|
||||
FF_LIST_FOR_EACH(FFPowerAdapterResult, item, results)
|
||||
{
|
||||
yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "description", &item->description);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "manufacturer", &item->manufacturer);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "modelName", &item->modelName);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "name", &item->name);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "serial", &item->serial);
|
||||
yyjson_mut_obj_add_int(doc, obj, "watts", item->watts);
|
||||
}
|
||||
ffStrbufDestroy(&item->manufacturer);
|
||||
ffStrbufDestroy(&item->description);
|
||||
ffStrbufDestroy(&item->modelName);
|
||||
ffStrbufDestroy(&item->name);
|
||||
ffStrbufDestroy(&item->serial);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,12 +200,6 @@ void ffGenerateSoundJsonResult(FF_MAYBE_UNUSED FFSoundOptions* options, yyjson_m
|
||||
return;
|
||||
}
|
||||
|
||||
if(result.length == 0)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", "No active sound devices found");
|
||||
return;
|
||||
}
|
||||
|
||||
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
|
||||
FF_LIST_FOR_EACH(FFSoundDevice, item, result)
|
||||
{
|
||||
|
@ -146,7 +146,7 @@ void ffGenerateUsersJsonResult(FF_MAYBE_UNUSED FFUsersOptions* options, yyjson_m
|
||||
if(error)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", error);
|
||||
goto exit;
|
||||
return;
|
||||
}
|
||||
|
||||
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
|
||||
@ -164,7 +164,6 @@ void ffGenerateUsersJsonResult(FF_MAYBE_UNUSED FFUsersOptions* options, yyjson_m
|
||||
yyjson_mut_obj_add_null(doc, obj, "loginTime");
|
||||
}
|
||||
|
||||
exit:
|
||||
FF_LIST_FOR_EACH(FFUserResult, user, results)
|
||||
{
|
||||
ffStrbufDestroy(&user->clientIp);
|
||||
|
@ -114,11 +114,6 @@ void ffGenerateWifiJsonResult(FF_MAYBE_UNUSED FFWifiOptions* options, yyjson_mut
|
||||
yyjson_mut_obj_add_str(doc, module, "error", error);
|
||||
return;
|
||||
}
|
||||
if(!result.length)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", "No Wifi interfaces found");
|
||||
return;
|
||||
}
|
||||
|
||||
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
|
||||
FF_LIST_FOR_EACH(FFWifiResult, wifi, result)
|
||||
|
Loading…
x
Reference in New Issue
Block a user