Add --format option to wslc version command - #41078
Merged
David Bennett (dkbennett) merged 11 commits intoJul 15, 2026
Merged
Conversation
Support `wslc version --format json`, which prints the version as
pretty-printed JSON of the form {"Client":{"Version":"..."}}. The
default and explicit `table` format keep the existing plain-text
output. Invalid format values are rejected with a localized error.
Add end-to-end tests covering the json, table, and invalid-format paths.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Author
|
@microsoft-github-policy-service agree company="Microsoft" |
Removed unnecessary comments regarding JSON output formatting.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the wslc version command to support a --format argument so users can choose between the existing table/plain-text output and a JSON representation of the client version.
Changes:
- Added
--format {json|table}argument support toVersionCommand, including JSON output formatting. - Introduced validation hooks for the new argument.
- Added E2E coverage for
version --format json,version --format table, and invalid format values.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/windows/wslc/commands/VersionCommand.h | Declares the new argument and validation overrides for VersionCommand. |
| src/windows/wslc/commands/VersionCommand.cpp | Implements --format handling and JSON/table output selection for wslc version. |
| test/windows/wslc/e2e/WSLCE2EGlobalTests.cpp | Adds E2E tests covering the new --format behavior. |
David Bennett (dkbennett)
left a comment
Member
There was a problem hiding this comment.
Few comments for some slight test improvements and a validation simplification.
Support `wslc version --format json`, which prints the version as
pretty-printed JSON of the form {"Client":{"Version":"..."}}. The
default and explicit `table` format keep the existing plain-text
output. Invalid format values are rejected by the existing automatic
Format argument validation.
Add functional e2e tests for the json and table output, and fast
command-line parsing cases (valid json/table, invalid) that exercise
the argument validation path.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The Format argument is validated automatically by the per-argument validation (ArgType::Format -> ValidateFormatTypeFromString), so the command-level override was dead code. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Addresses PR review nit. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
The FormatJson test now parses and compares the version value, so the exact-string helper is no longer referenced. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
test/windows/wslc/e2e/WSLCE2EGlobalTests.cpp:599
- GetVersionJsonMessage() is not referenced anywhere in this test class (the JSON test parses stdout instead), so it is dead code that can drift from the real output contract. Removing it keeps the test helper surface minimal.
} // namespace WSLCE2ETests
WSL_PACKAGE_VERSION is a narrow (UTF-8) compile definition, so wrapping it in std::wstring / passing it to WideToMultiByte did not compile. Assign and compare it directly as a std::string. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
David Bennett (dkbennett)
previously approved these changes
Jul 14, 2026
VersionCommand now exposes a --format argument, so the VersionCommand_HasNoArguments test (which asserted zero arguments) started failing in CI. Replace it with VersionCommand_HasFormatArgument, which verifies the --format argument's type, kind, and optionality. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
David Bennett (dkbennett)
approved these changes
Jul 15, 2026
David Bennett (dkbennett)
enabled auto-merge (squash)
July 15, 2026 00:09
David Bennett (dkbennett)
deleted the
user/ggarzia-MSFT/jsonVersionFormat
branch
July 15, 2026 01:42
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request adds support for a
--formatargument to theversioncommand, allowing users to choose between JSON and table (plain text) output formats. It also introduces validation for the argument, updates the command execution logic to handle both formats, and adds comprehensive end-to-end tests for the new functionality.New argument and validation for
versioncommand:--formatargument to theVersionCommand, enabling output in eitherjsonortableformat. The argument is validated to accept only these two formats; otherwise, an error is thrown. [1] [2] [3]Command execution logic enhancements:
ExecuteInternalmethod to output the version information as pretty-printed JSON when--format jsonis specified, or as plain text for--format table(or by default).End-to-end test coverage:
version --format json,version --format table, and invalid format values, ensuring robust validation and output.wslc version --format json, which prints the version as pretty-printed JSON of the form {"Client":{"Version":"..."}}. The default and explicittableformat keep the existing plain-text output. Invalid format values are rejected with a localized error.Add end-to-end tests covering the json, table, and invalid-format paths.
Summary of the Pull Request
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed