[WSLC] Add --workdir / -w option to 'wslc exec'#40041
[WSLC] Add --workdir / -w option to 'wslc exec'#40041ptrivedi wants to merge 5 commits intofeature/wsl-for-appsfrom
Conversation
Adds a --workdir (-w) argument to the exec command that sets the working directory inside the container for the executed process. Wires the value through ContainerOptions into WSLAProcessLauncher::SetWorkingDirectory. Co-authored-by: Pooja Trivedi <trivedipooja@microsoft.com> Co-Authored-By: Claude Sonnet 4.6
There was a problem hiding this comment.
Pull request overview
Adds support for specifying a working directory for wslc exec, wiring a new --workdir/-w CLI argument through argument parsing into ContainerOptions and down to the container exec launcher.
Changes:
- Add
ArgType::WorkDir(--workdir/-w) and include it inContainerExecCommand’s supported arguments. - Populate
ContainerOptions.WorkingDirectoryfrom parsed args and forward it intoWSLCProcessLauncherfor container exec. - Add/extend unit tests and command-line parsing test cases for the new option.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/windows/wslc/WSLCCLIExecutionUnitTests.cpp | Adds unit tests validating WorkingDirectory is set/empty appropriately and parsed via ContainerExecCommand. |
| test/windows/wslc/CommandLineTestCases.h | Adds command-line parsing cases covering --workdir / -w usage and a missing-value case. |
| src/windows/wslc/tasks/ContainerTasks.cpp | Reads WorkDir and sets ContainerOptions.WorkingDirectory. |
| src/windows/wslc/services/ContainerService.cpp | Applies WorkingDirectory to the WSLCProcessLauncher before launching container exec. |
| src/windows/wslc/services/ContainerModel.h | Adds WorkingDirectory field to ContainerOptions. |
| src/windows/wslc/commands/ContainerExecCommand.cpp | Registers WorkDir as an accepted argument for container exec. |
| src/windows/wslc/arguments/ArgumentDefinitions.h | Defines the new WorkDir argument (--workdir / -w). |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
AmelBawa-msft
left a comment
There was a problem hiding this comment.
LGTM! I suspect E2E tests will fail because we need to update the expected E2E test help messages. We should consider adding E2E tests as well but possibly in a separate PR since we still have a lot more E2E tests to write 😊
| _(User, "user", L"u", Kind::Value, L"User ID for the process (name|uid|uid:gid)") \ | ||
| _(Verbose, "verbose", L"v", Kind::Flag, L"Output verbose details") \ | ||
| _(Version, "version", L"v", Kind::Flag, L"Show version information for this tool") \ | ||
| _(WorkDir, "workdir", L"w", Kind::Value, L"Working directory inside the container") \ |
There was a problem hiding this comment.
Nit: Consider appending WorkDir at the end to preserve the sorted characteristics of the X-macro list
There was a problem hiding this comment.
+1 would prefer to keep this list sorted
dkbennett
left a comment
There was a problem hiding this comment.
Looks good, like the setting unit tests. An E2E with working directory would be nice but this looks like we are correctly setting the value in the CLI and passing it into the container runtime. Assuming that has tests this should be good, though it doesn't hurt to have a CLI E2E or two for this.
nit: sort order of _WorkDir as Amir mentioned.
| } | ||
|
|
||
| // Test: SetContainerOptionsFromArgs sets WorkingDirectory when --workdir is provided | ||
| TEST_METHOD(SetContainerOptionsFromArgs_WithWorkDir_SetsWorkingDirectory) |
There was a problem hiding this comment.
Clever unit tests here to verify the settings, we should add more like these later.
| _(User, "user", L"u", Kind::Value, L"User ID for the process (name|uid|uid:gid)") \ | ||
| _(Verbose, "verbose", L"v", Kind::Flag, L"Output verbose details") \ | ||
| _(Version, "version", L"v", Kind::Flag, L"Show version information for this tool") \ | ||
| _(WorkDir, "workdir", L"w", Kind::Value, L"Working directory inside the container") \ |
There was a problem hiding this comment.
+1 would prefer to keep this list sorted
Summary
--workdir/-woption towslc execto set the working directory inside the containerSetContainerOptionsFromArgsintoContainerOptions.WorkingDirectoryContainerService::ExecChanges
ArgumentDefinitions.h: registerWorkDirargument with long form--workdirand short alias-wContainerExecCommand.cpp: includeWorkDirin the exec command's argument listContainerModel.h: addWorkingDirectoryfield toContainerOptionsContainerTasks.cpp: readWorkDirarg and populateoptions.WorkingDirectoryContainerService.cpp: passWorkingDirectorywhen calling exec on the containerTests
CommandLineTestCases.h: parsing cases for--workdirand-w(valid and invalid)WSLCCLIExecutionUnitTests.cpp: 4 unit tests covering:SetContainerOptionsFromArgssetsWorkingDirectorywhen--workdiris providedSetContainerOptionsFromArgsleavesWorkingDirectoryempty when not provided--workdirlong option setsWorkingDirectory-wshort alias setsWorkingDirectoryTest plan
bin\<platform>\<target>\test.bat /name:*WSLCCLIExecutionUnitTests*wslc exec --workdir /app <container> pwdprints/appwslc exec -w /tmp <container> pwdprints/tmpwslc exec <container> pwduses the container's default working directory🤖 Generated with Claude Code