mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-12 10:22:12 +02:00
Command: add JSON printing support
This commit is contained in:
@@ -36,7 +36,7 @@ void ffPrintCommand(FFCommandOptions* options)
|
||||
|
||||
void ffInitCommandOptions(FFCommandOptions* options)
|
||||
{
|
||||
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_COMMAND_MODULE_NAME, ffParseCommandCommandOptions, ffParseCommandJsonObject, ffPrintCommand, NULL);
|
||||
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_COMMAND_MODULE_NAME, ffParseCommandCommandOptions, ffParseCommandJsonObject, ffPrintCommand, ffGenerateCommandJson);
|
||||
ffOptionInitModuleArg(&options->moduleArgs);
|
||||
|
||||
ffStrbufInitStatic(&options->shell,
|
||||
@@ -107,3 +107,32 @@ void ffParseCommandJsonObject(FFCommandOptions* options, yyjson_val* module)
|
||||
ffPrintError(FF_COMMAND_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
void ffGenerateCommandJson(FF_MAYBE_UNUSED FFCommandOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY result = ffStrbufCreate();
|
||||
const char* error = ffProcessAppendStdOut(&result, (char* const[]){
|
||||
options->shell.chars,
|
||||
#ifdef _WIN32
|
||||
"/c",
|
||||
#else
|
||||
"-c",
|
||||
#endif
|
||||
options->text.chars,
|
||||
NULL
|
||||
});
|
||||
|
||||
if(error)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", error);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!result.length)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", "No result printed");
|
||||
return;
|
||||
}
|
||||
|
||||
yyjson_mut_obj_add_strbuf(doc, module, "result", &result);
|
||||
}
|
||||
|
||||
@@ -9,3 +9,4 @@ void ffInitCommandOptions(FFCommandOptions* options);
|
||||
bool ffParseCommandCommandOptions(FFCommandOptions* options, const char* key, const char* value);
|
||||
void ffDestroyCommandOptions(FFCommandOptions* options);
|
||||
void ffParseCommandJsonObject(FFCommandOptions* options, yyjson_val* module);
|
||||
void ffGenerateCommandJson(FFCommandOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module);
|
||||
|
||||
Reference in New Issue
Block a user