-
Notifications
You must be signed in to change notification settings - Fork 1.7k
CLI: Initial support for version format option #40238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AmelBawa-msft
wants to merge
5
commits into
feature/wsl-for-apps
Choose a base branch
from
user/amelbawa/version-format
base: feature/wsl-for-apps
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+368
−19
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| /*++ | ||
|
|
||
| Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| Module Name: | ||
|
|
||
| VersionModel.h | ||
|
|
||
| Abstract: | ||
|
|
||
| This file contains the VersionModel definitions | ||
| --*/ | ||
|
|
||
| #pragma once | ||
|
|
||
| namespace wsl::windows::wslc::models { | ||
|
|
||
| #define WSLC_VERSION_ROW(key, value) std::format("{:<20}{}\n", key ":", value) | ||
|
|
||
| struct ClientVersion | ||
| { | ||
| std::string Version = WSL_PACKAGE_VERSION; | ||
| std::string GitCommit = COMMIT_HASH; | ||
| std::string Built = __DATE__ " " __TIME__; | ||
| std::string Os = "windows"; | ||
|
|
||
| #if defined(_AMD64_) | ||
| std::string Arch = "amd64"; | ||
| #elif defined(_ARM64_) | ||
| std::string Arch = "arm64"; | ||
| #else | ||
| std::string Arch = "unknown"; | ||
| #endif | ||
|
|
||
| NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(ClientVersion, Version, GitCommit, Built, Os, Arch); | ||
|
|
||
|
AmelBawa-msft marked this conversation as resolved.
|
||
| std::string ToString() const | ||
| { | ||
| std::stringstream ss; | ||
| ss << "Client:\n"; | ||
| ss << WSLC_VERSION_ROW(" Version", Version); | ||
| ss << WSLC_VERSION_ROW(" Git commit", GitCommit); | ||
| ss << WSLC_VERSION_ROW(" Built", Built); | ||
| ss << WSLC_VERSION_ROW(" OS/Arch", Os + "/" + Arch); | ||
| return ss.str(); | ||
| } | ||
| }; | ||
|
|
||
| struct ServerVersion | ||
| { | ||
| std::string Kernel = KERNEL_VERSION; | ||
| std::string WSLg = WSLG_VERSION; | ||
| std::string MSRDC = MSRDC_VERSION; | ||
| std::string Direct3D = DIRECT3D_VERSION; | ||
| std::string DXCore = DXCORE_VERSION; | ||
| std::string Windows = wsl::windows::common::helpers::GetWindowsVersionString(); | ||
|
|
||
| NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(ServerVersion, Kernel, WSLg, MSRDC, Direct3D, DXCore, Windows); | ||
|
|
||
|
AmelBawa-msft marked this conversation as resolved.
|
||
| std::string ToString() const | ||
| { | ||
| std::stringstream ss; | ||
| ss << "Server:\n"; | ||
| ss << WSLC_VERSION_ROW(" Linux kernel", Kernel); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These strings should be loc'd for table output in the CLI. |
||
| ss << WSLC_VERSION_ROW(" WSLg", WSLg); | ||
| ss << WSLC_VERSION_ROW(" MSRDC", MSRDC); | ||
| ss << WSLC_VERSION_ROW(" Direct3D", Direct3D); | ||
| ss << WSLC_VERSION_ROW(" DXCore", DXCore); | ||
| ss << WSLC_VERSION_ROW(" Windows", Windows); | ||
| return ss.str(); | ||
| } | ||
| }; | ||
|
|
||
| struct VersionInfo | ||
| { | ||
| ClientVersion Client{}; | ||
| ServerVersion Server{}; | ||
|
|
||
| NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(VersionInfo, Client, Server); | ||
|
|
||
| std::string ToString() const | ||
| { | ||
| std::stringstream ss; | ||
| ss << Client.ToString() << "\n"; | ||
| ss << Server.ToString(); | ||
| return ss.str(); | ||
| } | ||
| }; | ||
| #undef WSLC_VERSION_ROW | ||
| } // namespace wsl::windows::wslc::models | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /*++ | ||
|
|
||
| Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| Module Name: | ||
|
|
||
| VersionService.cpp | ||
|
|
||
| Abstract: | ||
|
|
||
| This file contains the VersionService implementation | ||
| --*/ | ||
|
|
||
| #include "precomp.h" | ||
| #include "VersionService.h" | ||
| #include "Command.h" | ||
|
|
||
| namespace wsl::windows::wslc::services { | ||
|
|
||
| using namespace wsl::shared::string; | ||
|
|
||
| std::wstring VersionService::GetVersionString() | ||
| { | ||
| return std::format(L"{} {}", s_ExecutableName, MultiByteToWide(VersionInfo().Client.Version)); | ||
|
AmelBawa-msft marked this conversation as resolved.
|
||
| } | ||
|
|
||
| const wsl::windows::wslc::models::VersionInfo& VersionService::VersionInfo() | ||
| { | ||
| static const wsl::windows::wslc::models::VersionInfo s_versionInfo{}; | ||
| return s_versionInfo; | ||
| } | ||
|
|
||
| } // namespace wsl::windows::wslc::services | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /*++ | ||
|
|
||
| Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| Module Name: | ||
|
|
||
| VersionService.h | ||
|
|
||
| Abstract: | ||
|
|
||
| This file contains the VersionService definition | ||
| --*/ | ||
| #pragma once | ||
|
|
||
| #include "VersionModel.h" | ||
| #include <wslc.h> | ||
|
|
||
| namespace wsl::windows::wslc::services { | ||
| struct VersionService | ||
| { | ||
| static std::wstring GetVersionString(); | ||
| static const wsl::windows::wslc::models::VersionInfo& VersionInfo(); | ||
| }; | ||
| } // namespace wsl::windows::wslc::services |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /*++ | ||
|
|
||
| Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| Module Name: | ||
|
|
||
| VersionTasks.cpp | ||
|
|
||
| Abstract: | ||
|
|
||
| Implementation of version command related execution logic. | ||
|
|
||
| --*/ | ||
| #include "precomp.h" | ||
| #include "Argument.h" | ||
| #include "ArgumentValidation.h" | ||
| #include "ContainerModel.h" | ||
| #include "VersionTasks.h" | ||
| #include "VersionService.h" | ||
| #include "CLIExecutionContext.h" | ||
| #include <wil/result_macros.h> | ||
| #include <wslc_schema.h> | ||
|
|
||
| using namespace wsl::shared; | ||
| using namespace wsl::shared::string; | ||
| using namespace wsl::windows::wslc::execution; | ||
| using namespace wsl::windows::wslc::models; | ||
| using namespace wsl::windows::wslc::services; | ||
| using namespace wsl::windows::common::wslutil; | ||
|
|
||
| namespace wsl::windows::wslc::task { | ||
|
|
||
| void GetVersionInfo(CLIExecutionContext& context) | ||
| { | ||
| context.Data.Add<Data::Version>(VersionService::VersionInfo()); | ||
| } | ||
|
|
||
| void ListVersionInfo(CLIExecutionContext& context) | ||
| { | ||
| WI_ASSERT(context.Data.Contains(Data::Version)); | ||
| auto& versionInfo = context.Data.Get<Data::Version>(); | ||
|
|
||
| FormatType format = FormatType::Table; // Default is table | ||
| if (context.Args.Contains(ArgType::Format)) | ||
| { | ||
| format = validation::GetFormatTypeFromString(context.Args.Get<ArgType::Format>()); | ||
| } | ||
|
|
||
| switch (format) | ||
| { | ||
| case FormatType::Json: | ||
| { | ||
| auto json = ToJson(versionInfo, c_jsonPrettyPrintIndent); | ||
| PrintMessage(MultiByteToWide(json)); | ||
| break; | ||
| } | ||
| case FormatType::Table: | ||
| { | ||
| PrintMessage(MultiByteToWide(versionInfo.ToString())); | ||
|
AmelBawa-msft marked this conversation as resolved.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should use the table output format all the other tables use. |
||
| break; | ||
| } | ||
| default: | ||
| THROW_HR(E_UNEXPECTED); | ||
| } | ||
| } | ||
| } // namespace wsl::windows::wslc::task | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /*++ | ||
|
|
||
| Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| Module Name: | ||
|
|
||
| VersionTasks.h | ||
|
|
||
| Abstract: | ||
|
|
||
| Declaration of version command execution tasks. | ||
| --*/ | ||
| #pragma once | ||
| #include "CLIExecutionContext.h" | ||
| #include "Task.h" | ||
|
|
||
| using wsl::windows::wslc::execution::CLIExecutionContext; | ||
|
|
||
| namespace wsl::windows::wslc::task { | ||
| void GetVersionInfo(CLIExecutionContext& context); | ||
| void ListVersionInfo(CLIExecutionContext& context); | ||
| } // namespace wsl::windows::wslc::task |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.