[WSLC] Add 'wslc version' subcommand#14547
[WSLC] Add 'wslc version' subcommand#14547ptrivedi wants to merge 9 commits intofeature/wsl-for-appsfrom
Conversation
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
|
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 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>
- 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
309d934 to
70b1e83
Compare
Added this, @AmelBawa-msft, PTAL |
VersionCommand::ExecuteInternal to avoid build issues
9afcebe to
bf04c87
Compare
| void VersionCommand::ExecuteInternal(CLIExecutionContext& context) const | ||
| { | ||
| UNREFERENCED_PARAMETER(context); | ||
| wsl::windows::common::wslutil::PrintMessage(std::format(L"{} v{}", s_ExecutableName, WSL_PACKAGE_VERSION)); |
There was a problem hiding this comment.
nit: I recommend dropping the v here to make parsing easier for callers
| TEST_METHOD(WSLCE2E_VersionCommand) | ||
| { | ||
| WSL2_TEST_ONLY(); | ||
| RunWslcAndVerify(L"version", {.Stdout = GetVersionMessage(), .Stderr = L"", .ExitCode = 0}); | ||
| } |
There was a problem hiding this comment.
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).
| return {L"Show version information."}; | ||
| } | ||
|
|
||
| std::wstring VersionCommand::LongDescription() const | ||
| { | ||
| return {L"Show version information for this tool."}; |
There was a problem hiding this comment.
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.
| 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(); |
| void VersionCommand::ExecuteInternal(CLIExecutionContext& context) const | ||
| { | ||
| UNREFERENCED_PARAMETER(context); | ||
| wsl::windows::common::wslutil::PrintMessage(std::format(L"{} v{}", s_ExecutableName, WSL_PACKAGE_VERSION)); | ||
| } |
There was a problem hiding this comment.
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.
- 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
Summary of the Pull Request
Adds a
versionsubcommand to the WSLC CLI so users can runwslc versionin addition to the existingwslc --versionflag. This follows the subcommand pattern used by other WSLC commands.Changes
commands/VersionCommand.h/commands/VersionCommand.cpp— newVersionCommandthat printswslc v<version>commands/RootCommand.cpp— registersVersionCommandas a subcommand of the rootTests
CommandLineTestCases.h— parsing test cases forwslc version,wslc version --help, and invalid usageWSLCCLICommandUnitTests.cpp— unit tests verifying command name, no subcommands, no extra arguments, and presence in root command's subcommand listValidation Steps Performed
Verified manually that
wslc versionprints the version string identically towslc --version.TODO
wslc --versioncan be removed now thatwslc versionexists.🤖 Generated with Claude Code