Skip to content

Add --format option to wslc version command - #41078

Merged
David Bennett (dkbennett) merged 11 commits into
masterfrom
user/ggarzia-MSFT/jsonVersionFormat
Jul 15, 2026
Merged

Add --format option to wslc version command#41078
David Bennett (dkbennett) merged 11 commits into
masterfrom
user/ggarzia-MSFT/jsonVersionFormat

Conversation

@ggarzia-MSFT

Copy link
Copy Markdown
Contributor

This pull request adds support for a --format argument to the version command, 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 version command:

  • Added a --format argument to the VersionCommand, enabling output in either json or table format. The argument is validated to accept only these two formats; otherwise, an error is thrown. [1] [2] [3]

Command execution logic enhancements:

  • Updated the ExecuteInternal method to output the version information as pretty-printed JSON when --format json is specified, or as plain text for --format table (or by default).

End-to-end test coverage:

  • Added new E2E tests to verify correct behavior for version --format json, version --format table, and invalid format values, ensuring robust validation and output.
  • Added a helper method to generate the expected JSON output for testing.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.

Summary of the Pull Request

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

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>
Copilot AI review requested due to automatic review settings July 14, 2026 21:22
@ggarzia-MSFT
ggarzia-MSFT requested a review from a team as a code owner July 14, 2026 21:22
@ggarzia-MSFT

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree company="Microsoft"

Removed unnecessary comments regarding JSON output formatting.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 to VersionCommand, 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.

Comment thread src/windows/wslc/commands/VersionCommand.cpp Outdated
Comment thread src/windows/wslc/commands/VersionCommand.cpp Outdated
Comment thread test/windows/wslc/e2e/WSLCE2EGlobalTests.cpp Outdated
Copilot AI review requested due to automatic review settings July 14, 2026 21:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread test/windows/wslc/e2e/WSLCE2EGlobalTests.cpp
Comment thread test/windows/wslc/e2e/WSLCE2EGlobalTests.cpp Outdated
Comment thread src/windows/wslc/commands/VersionCommand.cpp Outdated

@dkbennett David Bennett (dkbennett) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few comments for some slight test improvements and a validation simplification.

Comment thread src/windows/wslc/commands/VersionCommand.cpp Outdated
Comment thread test/windows/wslc/e2e/WSLCE2EGlobalTests.cpp Outdated
ggarzia-MSFT and others added 2 commits July 14, 2026 14:48
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>
Copilot AI review requested due to automatic review settings July 14, 2026 21:54
Comment thread test/windows/wslc/e2e/WSLCE2EGlobalTests.cpp Outdated
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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread src/windows/wslc/commands/VersionCommand.cpp Outdated
Comment thread test/windows/wslc/e2e/WSLCE2EGlobalTests.cpp
Addresses PR review nit.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 14, 2026 22:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread test/windows/wslc/e2e/WSLCE2EGlobalTests.cpp
Comment thread test/windows/wslc/e2e/WSLCE2EGlobalTests.cpp
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 14, 2026 22:08
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

Comment thread test/windows/wslc/e2e/WSLCE2EGlobalTests.cpp
Comment thread test/windows/wslc/e2e/WSLCE2EGlobalTests.cpp Outdated
Comment thread test/windows/wslc/e2e/WSLCE2EGlobalTests.cpp
Comment thread src/windows/wslc/commands/VersionCommand.cpp
Copilot AI review requested due to automatic review settings July 14, 2026 22:13
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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread test/windows/wslc/e2e/WSLCE2EGlobalTests.cpp
Comment thread src/windows/wslc/commands/VersionCommand.cpp
Copilot AI review requested due to automatic review settings July 14, 2026 22:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread test/windows/wslc/e2e/WSLCE2EGlobalTests.cpp
Comment thread src/windows/wslc/commands/VersionCommand.cpp
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>
Copilot AI review requested due to automatic review settings July 14, 2026 22:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread test/windows/wslc/e2e/WSLCE2EGlobalTests.cpp
Comment thread src/windows/wslc/commands/VersionCommand.cpp
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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread src/windows/wslc/commands/VersionCommand.cpp
@dkbennett
David Bennett (dkbennett) enabled auto-merge (squash) July 15, 2026 00:09
@dkbennett
David Bennett (dkbennett) merged commit 66abe46 into master Jul 15, 2026
12 checks passed
@dkbennett
David Bennett (dkbennett) deleted the user/ggarzia-MSFT/jsonVersionFormat branch July 15, 2026 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants