master
h 63 lines 1.63 KB
Raw
1 /*++
2
3 Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 CLIExecutionContext.h
8
9 Abstract:
10
11 Declaration of CLI execution context.
12
13 --*/
14 #pragma once
15 #include "ArgMap.h"
16 #include "ExecutionContextData.h"
17 #include "Terminal.h"
18 #include <optional>
19
20 namespace wsl::windows::wslc::execution {
21
22 struct CLIExecutionContext : public wsl::windows::common::ExecutionContext
23 {
24 CLIExecutionContext() : wsl::windows::common::ExecutionContext(wsl::windows::common::Context::WslC)
25 {
26 }
27 ~CLIExecutionContext() override = default;
28
29 NON_COPYABLE(CLIExecutionContext);
30 NON_MOVABLE(CLIExecutionContext);
31
32 // Per-subcommand arguments parsed by the resolved leaf Command.
33 argument::ArgMap Args;
34
35 // Global options parsed from tokens that appear before any subcommand
36 // (e.g. `wslc <global-option> image list`). Populated early in CoreMain.
37 argument::ArgMap GlobalArgs;
38
39 // Map of data stored in the context.
40 DataMap Data;
41
42 // Central output terminal for all user-facing status messages.
43 Terminal Terminal;
44
45 // Process exit code set by tasks like Run/Exec.
46 std::optional<int> ExitCode;
47
48 // Event signaled when the user presses Ctrl-C.
49 wil::unique_event CancelEvent;
50
51 HANDLE CreateCancelEvent();
52
53 // Applies and freezes environment-only global options before command-line parsing reports errors.
54 void ApplyGlobalEnvironmentOptions();
55
56 // Prints a caught error to stderr.
57 void ReportError(HRESULT result);
58
59 // Drops the collected error so a later failure in the same invocation reports its own message.
60 void ClearError();
61 };
62
63 } // namespace wsl::windows::wslc::execution