From e00c793343fcfcdca7612023c7c7e7f163f29088 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Fri, 31 May 2024 21:16:16 -0300 Subject: [PATCH] Obey `--verbose` in HTTP fallback resolver logs (#21) Signed-off-by: Juan Cruz Viotti --- src/utils.cc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/utils.cc b/src/utils.cc index 7305aba2..ec9478a2 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -127,7 +127,9 @@ auto pretty_evaluate_callback( std::cerr << "\"\n"; } -static auto fallback_resolver(std::string_view identifier) +static auto fallback_resolver( + const std::map> &options, + std::string_view identifier) -> std::future> { auto official_result{ sourcemeta::jsontoolkit::official_resolver(identifier).get()}; @@ -147,9 +149,8 @@ static auto fallback_resolver(std::string_view identifier) return promise.get_future(); } - // TODO: Only print in verbose mode - std::cerr << "-- Attempting to fetch over HTTP: " << identifier << "\n"; - + log_verbose(options) << "Attempting to fetch over HTTP: " << identifier + << "\n"; sourcemeta::hydra::http::ClientRequest request{std::string{identifier}}; request.method(sourcemeta::hydra::http::Method::GET); sourcemeta::hydra::http::ClientResponse response{request.send().get()}; @@ -168,7 +169,13 @@ static auto fallback_resolver(std::string_view identifier) auto resolver(const std::map> &options, const bool remote) -> sourcemeta::jsontoolkit::SchemaResolver { sourcemeta::jsontoolkit::MapSchemaResolver dynamic_resolver{ - remote ? fallback_resolver : sourcemeta::jsontoolkit::official_resolver}; + [&remote, &options](std::string_view identifier) { + if (remote) { + return fallback_resolver(options, identifier); + } else { + return sourcemeta::jsontoolkit::official_resolver(identifier); + } + }}; if (options.contains("resolve")) { for (const auto &schema_path : options.at("resolve")) {