|
4 | 4 | #include "DscCommandBase.h"
|
5 | 5 | #include "DscCommand.h"
|
6 | 6 | #include <winget/Runtime.h>
|
| 7 | +#include <winget/StdErrLogger.h> |
7 | 8 |
|
8 | 9 | #define WINGET_DSC_FUNCTION_FOREACH(_macro_) \
|
9 | 10 | _macro_(Get); \
|
@@ -201,8 +202,7 @@ namespace AppInstaller::CLI
|
201 | 202 | void DscCommandBase::ExecuteInternal(Execution::Context& context) const
|
202 | 203 | {
|
203 | 204 | context.Reporter.SetChannel(Execution::Reporter::Channel::Json);
|
204 |
| - |
205 |
| - // TODO: Consider adding a stderr logger |
| 205 | + Logging::StdErrLogger::Add(); |
206 | 206 |
|
207 | 207 | #define WINGET_DSC_FUNCTION_ARGUMENT(_function_) \
|
208 | 208 | if (context.Args.Contains(Execution::Args::Type::DscResourceFunction ## _function_)) \
|
@@ -266,18 +266,33 @@ namespace AppInstaller::CLI
|
266 | 266 |
|
267 | 267 | #undef WINGET_DSC_FUNCTION_METHOD
|
268 | 268 |
|
269 |
| - std::optional<Json::Value> DscCommandBase::GetJsonFromInput(Execution::Context& context) const |
| 269 | + std::optional<Json::Value> DscCommandBase::GetJsonFromInput(Execution::Context& context, bool terminateContextOnError) const |
270 | 270 | {
|
271 |
| - Json::Value result; |
272 |
| - Json::CharReaderBuilder builder; |
273 |
| - Json::String errors; |
274 |
| - if (!Json::parseFromStream(builder, context.Reporter.RawInputStream(), &result, &errors)) |
| 271 | + // Don't attempt to read from an interactive stream as this will just block |
| 272 | + if (!context.Reporter.InputStreamIsInteractive()) |
275 | 273 | {
|
| 274 | + AICLI_LOG(CLI, Verbose, << "Reading Json from input stream..."); |
| 275 | + |
| 276 | + Json::Value result; |
| 277 | + Json::CharReaderBuilder builder; |
| 278 | + Json::String errors; |
| 279 | + if (Json::parseFromStream(builder, context.Reporter.RawInputStream(), &result, &errors)) |
| 280 | + { |
| 281 | + AICLI_LOG(CLI, Info, << "Json from input stream:\n" << Json::writeString(Json::StreamWriterBuilder{}, result)); |
| 282 | + return result; |
| 283 | + } |
| 284 | + |
276 | 285 | AICLI_LOG(CLI, Error, << "Failed to read input JSON: " << errors);
|
277 |
| - AICLI_TERMINATE_CONTEXT_RETURN(APPINSTALLER_CLI_ERROR_JSON_INVALID_FILE, std::nullopt); |
278 | 286 | }
|
279 | 287 |
|
280 |
| - return result; |
| 288 | + if (terminateContextOnError) |
| 289 | + { |
| 290 | + AICLI_TERMINATE_CONTEXT_RETURN(APPINSTALLER_CLI_ERROR_JSON_INVALID_FILE, std::nullopt); |
| 291 | + } |
| 292 | + else |
| 293 | + { |
| 294 | + return std::nullopt; |
| 295 | + } |
281 | 296 | }
|
282 | 297 |
|
283 | 298 | void DscCommandBase::WriteJsonOutputLine(Execution::Context& context, const Json::Value& value) const
|
|
0 commit comments