From 4449173b3dc5798a7f57f643f268f423f284da39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 12 Sep 2023 20:36:00 +0800 Subject: [PATCH] Version: support JSON config --- src/modules/version/version.c | 18 ++++++++++++++++-- src/modules/version/version.h | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/modules/version/version.c b/src/modules/version/version.c index 0805c1ee4..34b8e0642 100644 --- a/src/modules/version/version.c +++ b/src/modules/version/version.c @@ -8,7 +8,7 @@ void ffPrintVersion(FFVersionOptions* options) { - FFVersionResult result = {}; + FFVersionResult result; ffDetectVersion(&result); if(options->moduleArgs.outputFormat.length == 0) @@ -31,7 +31,7 @@ void ffPrintVersion(FFVersionOptions* options) void ffInitVersionOptions(FFVersionOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_VERSION_MODULE_NAME, ffParseVersionCommandOptions, ffParseVersionJsonObject, ffPrintVersion, NULL); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_VERSION_MODULE_NAME, ffParseVersionCommandOptions, ffParseVersionJsonObject, ffPrintVersion, ffGenerateVersionJson); ffOptionInitModuleArg(&options->moduleArgs); } @@ -66,3 +66,17 @@ void ffParseVersionJsonObject(FFVersionOptions* options, yyjson_val* module) ffPrintError(FF_VERSION_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key); } } + +void ffGenerateVersionJson(FF_MAYBE_UNUSED FFVersionOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + FFVersionResult result; + ffDetectVersion(&result); + + yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result"); + yyjson_mut_obj_add_str(doc, obj, "projectName", result.projectName); + yyjson_mut_obj_add_str(doc, obj, "architecture", result.architecture); + yyjson_mut_obj_add_str(doc, obj, "version", result.version); + yyjson_mut_obj_add_str(doc, obj, "versionTweak", result.versionTweak); + yyjson_mut_obj_add_str(doc, obj, "cmakeBuiltType", result.cmakeBuiltType); + yyjson_mut_obj_add_bool(doc, obj, "debugMode", result.debugMode); +} diff --git a/src/modules/version/version.h b/src/modules/version/version.h index ef423b36e..bb1e4c15f 100644 --- a/src/modules/version/version.h +++ b/src/modules/version/version.h @@ -9,3 +9,4 @@ void ffInitVersionOptions(FFVersionOptions* options); bool ffParseVersionCommandOptions(FFVersionOptions* options, const char* key, const char* value); void ffDestroyVersionOptions(FFVersionOptions* options); void ffParseVersionJsonObject(FFVersionOptions* options, yyjson_val* module); +void ffGenerateVersionJson(FFVersionOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module);