diff --git a/src/modules/weather/weather.c b/src/modules/weather/weather.c index d71dbef74..609f5f329 100644 --- a/src/modules/weather/weather.c +++ b/src/modules/weather/weather.c @@ -33,7 +33,7 @@ void ffPrintWeather(FFWeatherOptions* options) void ffInitWeatherOptions(FFWeatherOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WEATHER_MODULE_NAME, ffParseWeatherCommandOptions, ffParseWeatherJsonObject, ffPrintWeather, NULL); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WEATHER_MODULE_NAME, ffParseWeatherCommandOptions, ffParseWeatherJsonObject, ffPrintWeather, ffGenerateWeatherJson); ffOptionInitModuleArg(&options->moduleArgs); ffStrbufInit(&options->location); @@ -110,3 +110,17 @@ void ffParseWeatherJsonObject(FFWeatherOptions* options, yyjson_val* module) ffPrintError(FF_WEATHER_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key); } } + +void ffGenerateWeatherJson(FFWeatherOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + FF_STRBUF_AUTO_DESTROY result = ffStrbufCreate(); + const char* error = ffDetectWeather(options, &result); + + if (error) + { + yyjson_mut_obj_add_str(doc, module, "error", error); + return; + } + + yyjson_mut_obj_add_strbuf(doc, module, "result", &result); +} diff --git a/src/modules/weather/weather.h b/src/modules/weather/weather.h index 888606957..a76940244 100644 --- a/src/modules/weather/weather.h +++ b/src/modules/weather/weather.h @@ -11,3 +11,4 @@ void ffInitWeatherOptions(FFWeatherOptions* options); bool ffParseWeatherCommandOptions(FFWeatherOptions* options, const char* key, const char* value); void ffDestroyWeatherOptions(FFWeatherOptions* options); void ffParseWeatherJsonObject(FFWeatherOptions* options, yyjson_val* module); +void ffGenerateWeatherJson(FFWeatherOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module);