master
cpp 68 lines 1.5 KB
Raw
1 /*++
2
3 Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 VersionCommand.cpp
8
9 Abstract:
10
11 Implementation of the version command.
12
13 --*/
14
15 #include "VersionCommand.h"
16 #include "ArgumentConvertedTypes.h"
17 #include "CLIExecutionContext.h"
18 #include "JsonUtils.h"
19
20 using namespace wsl::shared;
21 using namespace wsl::shared::string;
22 using namespace wsl::windows::wslc::execution;
23 using namespace wsl::windows::wslc::models;
24
25 namespace wsl::windows::wslc {
26 std::vector<Argument> VersionCommand::GetArguments() const
27 {
28 return {
29 Argument::Create(ArgType::Format),
30 };
31 }
32
33 std::wstring VersionCommand::ShortDescription() const
34 {
35 return Localization::WSLCCLI_VersionDesc();
36 }
37
38 std::wstring VersionCommand::LongDescription() const
39 {
40 return Localization::WSLCCLI_VersionLongDesc();
41 }
42
43 void VersionCommand::PrintVersion(Terminal& terminal)
44 {
45 terminal.Output(L"{} {}\n", s_ExecutableName, WSL_PACKAGE_VERSION);
46 }
47
48 void VersionCommand::ExecuteInternal(CLIExecutionContext& context) const
49 {
50 const auto format = context.Args.GetValue<ArgType::Format>(FormatType::Table);
51
52 switch (format)
53 {
54 case FormatType::Json:
55 {
56 nlohmann::json root;
57 root["Client"]["Version"] = std::string{WSL_PACKAGE_VERSION};
58 context.Terminal.Output(L"{}\n", MultiByteToWide(root.dump(c_jsonCompactIndent)));
59 break;
60 }
61 case FormatType::Table:
62 PrintVersion(context.Terminal);
63 break;
64 default:
65 THROW_HR(E_UNEXPECTED);
66 }
67 }
68 } // namespace wsl::windows::wslc