| 1 | /*++ |
| 2 | |
| 3 | Copyright (c) Microsoft. All rights reserved. |
| 4 | |
| 5 | --*/ |
| 6 | #include "precomp.h" |
| 7 | #include "Argument.h" |
| 8 | #include "CLIExecutionContext.h" |
| 9 | |
| 10 | using namespace wsl::shared; |
| 11 | using namespace wsl::windows::common; |
| 12 | |
| 13 | namespace wsl::windows::wslc::execution { |
| 14 | |
| 15 | HANDLE CLIExecutionContext::CreateCancelEvent() |
| 16 | { |
| 17 | WI_ASSERT(!CancelEvent); |
| 18 | CancelEvent.create(wil::EventOptions::ManualReset); |
| 19 | return CancelEvent.get(); |
| 20 | } |
| 21 | |
| 22 | void CLIExecutionContext::ApplyGlobalEnvironmentOptions() |
| 23 | { |
| 24 | // NoColor is environment-only and resolved before any output. Freezing it keeps the terminal |
| 25 | // color state consistent for the entire invocation. |
| 26 | Terminal.SetNoColor(GlobalArgs.GetValue<ArgType::NoColor>()); |
| 27 | } |
| 28 | |
| 29 | void CLIExecutionContext::ReportError(HRESULT result) |
| 30 | { |
| 31 | std::wstring message; |
| 32 | if (const auto& reported = ReportedError()) |
| 33 | { |
| 34 | const auto strings = wslutil::ErrorToString(*reported); |
| 35 | message = strings.Message.empty() ? strings.Code : strings.Message; |
| 36 | } |
| 37 | |
| 38 | Terminal.Error(L"{}\n", Localization::MessageErrorCode(message, wslutil::ErrorCodeToString(result))); |
| 39 | } |
| 40 | |
| 41 | void CLIExecutionContext::ClearError() |
| 42 | { |
| 43 | m_error.reset(); |
| 44 | } |
| 45 | |
| 46 | } // namespace wsl::windows::wslc::execution |