@samitouri / QOSAMI-WSL / commits / 83d59d4b

Fix: Fail and warn the user when --uninstall is given parameters (#14524)

Fail and warn the user when --uninstall is given parameters.

Feng Wang committed Mar 25, 2026 at 13:08 UTC 83d59d4b4a31b457183caa02d11dff5e5c328d16
3 files changed +21
localization/strings/en-US/Resources.resw
+4
@@ -960,6 +960,10 @@ Falling back to NAT networking.</value>
960 <value>Update failed (exit code: {}).</value>
961 <comment>{FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated</comment>
962 </data>
963 + <data name="MessageUninstallNoArguments" xml:space="preserve">
964 + <value>{} does not take any arguments. To unregister a distribution, use {} instead.</value>
965 + <comment>{FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated</comment>
966 + </data>
967 <data name="MessageUninstallFailed" xml:space="preserve">
968 <value>Uninstall failed (exit code: {}).</value>
969 <comment>{FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated</comment>
src/windows/common/WslClient.cpp
+9
@@ -1751,6 +1751,15 @@ int WslMain(_In_ std::wstring_view commandLine)
1751 }
1752 else if (argument == WSL_UNINSTALL_ARG)
1753 {
1754 + commandLine = wsl::windows::common::helpers::ConsumeArgument(commandLine, argument);
1755 + argument = wsl::windows::common::helpers::ParseArgument(commandLine);
1756 + if (!argument.empty())
1757 + {
1758 + wsl::windows::common::wslutil::PrintMessage(
1759 + Localization::MessageUninstallNoArguments(WSL_UNINSTALL_ARG, WSL_UNREGISTER_ARG), stdout);
1760 + return exitCode;
1761 + }
1762 +
1763 return Uninstall();
1764 }
1765 else
test/windows/UnitTests.cpp
+8
@@ -6561,5 +6561,13 @@ Error code: Wsl/InstallDistro/WSL_E_INVALID_JSON\r\n",
6561 VERIFY_ARE_EQUAL(result.ExitCode, 0);
6562 }
6563
6564 + TEST_METHOD(UninstallRejectsArguments)
6565 + {
6566 + VerifyOutput(
6567 + L"--uninstall Distro",
6568 + wsl::shared::Localization::MessageUninstallNoArguments(WSL_UNINSTALL_ARG, WSL_UNREGISTER_ARG) + L"\r\n",
6569 + -1);
6570 + }
6571 +
6572 }; // namespace UnitTests
6573 } // namespace UnitTests