Shell: JSON format support

This commit is contained in:
李通洲
2023-09-08 16:33:19 +08:00
parent aff4a57092
commit d97b16950c
2 changed files with 22 additions and 1 deletions
+21 -1
View File
@@ -45,7 +45,7 @@ void ffPrintShell(FFShellOptions* options)
void ffInitShellOptions(FFShellOptions* options)
{
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_SHELL_MODULE_NAME, ffParseShellCommandOptions, ffParseShellJsonObject, ffPrintShell, NULL);
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_SHELL_MODULE_NAME, ffParseShellCommandOptions, ffParseShellJsonObject, ffPrintShell, ffGenerateShellJson);
ffOptionInitModuleArg(&options->moduleArgs);
}
@@ -80,3 +80,23 @@ void ffParseShellJsonObject(FFShellOptions* options, yyjson_val* module)
ffPrintError(FF_SHELL_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
}
void ffGenerateShellJson(FF_MAYBE_UNUSED FFShellOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
const FFTerminalShellResult* result = ffDetectTerminalShell();
if(result->shellProcessName.length == 0)
{
yyjson_mut_obj_add_str(doc, module, "error", "Couldn't detect shell");
return;
}
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
yyjson_mut_obj_add_strbuf(doc, obj, "processName", &result->shellProcessName);
yyjson_mut_obj_add_strbuf(doc, obj, "exe", &result->shellExe);
yyjson_mut_obj_add_strcpy(doc, obj, "exeName", result->shellExeName);
yyjson_mut_obj_add_strbuf(doc, obj, "version", &result->shellVersion);
yyjson_mut_obj_add_strbuf(doc, obj, "userShellExe", &result->userShellExe);
yyjson_mut_obj_add_strcpy(doc, obj, "userShellExeName", result->userShellExeName);
yyjson_mut_obj_add_strbuf(doc, obj, "userShellVersion", &result->userShellVersion);
}
+1
View File
@@ -9,3 +9,4 @@ void ffInitShellOptions(FFShellOptions* options);
bool ffParseShellCommandOptions(FFShellOptions* options, const char* key, const char* value);
void ffDestroyShellOptions(FFShellOptions* options);
void ffParseShellJsonObject(FFShellOptions* options, yyjson_val* module);
void ffGenerateShellJson(FFShellOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module);