Skip to content

[WSLC] Add 'wslc version' subcommand#14547

Open
ptrivedi wants to merge 9 commits intofeature/wsl-for-appsfrom
user/ptrivedi/cli-version
Open

[WSLC] Add 'wslc version' subcommand#14547
ptrivedi wants to merge 9 commits intofeature/wsl-for-appsfrom
user/ptrivedi/cli-version

Conversation

@ptrivedi
Copy link
Copy Markdown

@ptrivedi ptrivedi commented Mar 26, 2026

Summary of the Pull Request

Adds a version subcommand to the WSLC CLI so users can run wslc version in addition to the existing wslc --version flag. This follows the subcommand pattern used by other WSLC commands.

Changes

  • commands/VersionCommand.h / commands/VersionCommand.cpp — new VersionCommand that prints wslc v<version>
  • commands/RootCommand.cpp — registers VersionCommand as a subcommand of the root

Tests

  • CommandLineTestCases.h — parsing test cases for wslc version, wslc version --help, and invalid usage
  • WSLCCLICommandUnitTests.cpp — unit tests verifying command name, no subcommands, no extra arguments, and presence in root command's subcommand list

Validation Steps Performed

Verified manually that wslc version prints the version string identically to wslc --version.

TODO

  • Discuss and decide with the team whether wslc --version can be removed now that wslc version exists.

🤖 Generated with Claude Code

Adds a 'version' subcommand to the WSLC CLI as an alternative to the
existing '--version' flag, following the subcommand pattern used by
other WSLC commands. Includes unit tests for command structure and
command-line parsing.

Co-authored-by: Pooja Trivedi <trivedipooja@microsoft.com>
Co-Authored-By: Claude Sonnet 4.6
@ptrivedi ptrivedi requested a review from a team as a code owner March 26, 2026 20:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

@ptrivedi ptrivedi requested review from AmelBawa-msft and dkbennett and removed request for damanm24 and jstarks March 26, 2026 20:08
@ptrivedi ptrivedi changed the base branch from master to feature/wsl-for-apps March 26, 2026 20:11
@ptrivedi ptrivedi requested a review from a team as a code owner March 26, 2026 20:11
@benhillis benhillis requested a review from Copilot March 26, 2026 20:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 no new comments.

@AmelBawa-msft
Copy link
Copy Markdown

LGTM! I suspect the E2E test will fail for WSLCE2EGlobalTests class because we need to update the help message and potentially add some E2E tests for version (e.g. ensure returns exit code 0, the expected version in stdout, empty string in stderr).

e.g.

RunWslcAndVerify("version", { .Stdout = std::format(L"{} v{}", ..., ...),  .Stderr = L"",  .ExitCode = 0});

…dition

Update expected help output in WSLCE2EGlobalTests to include the newly
added 'version' subcommand, fixing WSLCE2E_HelpCommand and
WSLCE2E_InvalidCommand_DisplaysErrorMessage test failures.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 27, 2026 18:27
@ptrivedi ptrivedi marked this pull request as draft March 27, 2026 18:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 6 out of 6 changed files in this pull request and generated 1 comment.

@ptrivedi ptrivedi marked this pull request as ready for review March 29, 2026 03:15
Copilot AI review requested due to automatic review settings March 29, 2026 03:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 6 out of 6 changed files in this pull request and generated 2 comments.

- Add WSLCE2E_VersionCommand E2E test in WSLCE2EGlobalTests verifying
  stdout, empty stderr, and exit code for 'wslc version'
- Add assertion to VersionCommand_HasNoArguments unit test to verify
  only the auto-added --help argument is present

Authored-By: Pooja Trivedi <trivedipooja@microsoft.com>
Co-Authored-By: Claude Sonnet 4.6
@ptrivedi ptrivedi force-pushed the user/ptrivedi/cli-version branch from 309d934 to 70b1e83 Compare March 29, 2026 04:04
@ptrivedi
Copy link
Copy Markdown
Author

LGTM! I suspect the E2E test will fail for WSLCE2EGlobalTests class because we need to update the help message and potentially add some E2E tests for version (e.g. ensure returns exit code 0, the expected version in stdout, empty string in stderr).

e.g.

RunWslcAndVerify("version", { .Stdout = std::format(L"{} v{}", ..., ...),  .Stderr = L"",  .ExitCode = 0});

Added this, @AmelBawa-msft, PTAL

Copilot AI review requested due to automatic review settings March 29, 2026 04:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 6 out of 6 changed files in this pull request and generated no new comments.

VersionCommand::ExecuteInternal to avoid build issues
@ptrivedi ptrivedi force-pushed the user/ptrivedi/cli-version branch from 9afcebe to bf04c87 Compare March 29, 2026 04:23
Copilot AI review requested due to automatic review settings March 29, 2026 04:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 6 out of 6 changed files in this pull request and generated no new comments.

void VersionCommand::ExecuteInternal(CLIExecutionContext& context) const
{
UNREFERENCED_PARAMETER(context);
wsl::windows::common::wslutil::PrintMessage(std::format(L"{} v{}", s_ExecutableName, WSL_PACKAGE_VERSION));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: I recommend dropping the v here to make parsing easier for callers

Copilot AI review requested due to automatic review settings April 3, 2026 21:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 6 out of 6 changed files in this pull request and generated 3 comments.

Comment on lines +54 to +58
TEST_METHOD(WSLCE2E_VersionCommand)
{
WSL2_TEST_ONLY();
RunWslcAndVerify(L"version", {.Stdout = GetVersionMessage(), .Stderr = L"", .ExitCode = 0});
}
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

WSLCE2E_HelpCommand and invalid-command tests build expected help output via GetAvailableCommands(), but adding VersionCommand to RootCommand means the real --help output will now include a version entry. Without updating the expected help message builder, the existing help-related E2E tests will fail due to output mismatch (even if wslc version itself works).

Copilot uses AI. Check for mistakes.
Comment on lines +21 to +26
return {L"Show version information."};
}

std::wstring VersionCommand::LongDescription() const
{
return {L"Show version information for this tool."};
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

VersionCommand::ShortDescription/LongDescription introduce hard-coded English strings, while other WSLC commands return localized strings via Localization::... (e.g., ContainerListCommand uses Localization::WSLCCLI_ContainerListDesc() / ...LongDesc()). This will make wslc --help partially unlocalized once version is listed as a subcommand; consider adding localized resources and returning them here for consistency.

Suggested change
return {L"Show version information."};
}
std::wstring VersionCommand::LongDescription() const
{
return {L"Show version information for this tool."};
return Localization::WSLCCLI_VersionDesc();
}
std::wstring VersionCommand::LongDescription() const
{
return Localization::WSLCCLI_VersionLongDesc();

Copilot uses AI. Check for mistakes.
Comment on lines +29 to +33
void VersionCommand::ExecuteInternal(CLIExecutionContext& context) const
{
UNREFERENCED_PARAMETER(context);
wsl::windows::common::wslutil::PrintMessage(std::format(L"{} v{}", s_ExecutableName, WSL_PACKAGE_VERSION));
}
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

The version output formatting is duplicated here and in RootCommand’s --version handling (PrintMessage(std::format(L"{} v{}", ...))). To avoid the two paths drifting over time, consider centralizing the version-printing logic (shared helper or utility) and reuse it from both the flag and the subcommand.

Copilot uses AI. Check for mistakes.
- Use Localization::WSLCCLI_VersionDesc/LongDesc instead of hard-coded strings; add entries to en-US Resources.resw
- Centralize version printing in VersionCommand::PrintVersion(); reuse from RootCommand --version flag
- Drop 'v' prefix from version output per OneBlue's feedback
- Add 'version' entry to E2E GetAvailableCommands() to fix WSLCE2E_HelpCommand and WSLCE2E_InvalidCommand_DisplaysErrorMessage

Co-Authored-By: Pooja Trivedi
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.

5 participants