Skip to content

[WSLC] Add --workdir / -w option to 'wslc exec'#40041

Open
ptrivedi wants to merge 5 commits intofeature/wsl-for-appsfrom
user/ptrivedi/exec-workingdir
Open

[WSLC] Add --workdir / -w option to 'wslc exec'#40041
ptrivedi wants to merge 5 commits intofeature/wsl-for-appsfrom
user/ptrivedi/exec-workingdir

Conversation

@ptrivedi
Copy link
Copy Markdown

@ptrivedi ptrivedi commented Mar 30, 2026

Summary

  • Adds --workdir / -w option to wslc exec to set the working directory inside the container
  • Passes the value through SetContainerOptionsFromArgs into ContainerOptions.WorkingDirectory
  • Forwards the working directory to the container service via ContainerService::Exec

Changes

  • ArgumentDefinitions.h: register WorkDir argument with long form --workdir and short alias -w
  • ContainerExecCommand.cpp: include WorkDir in the exec command's argument list
  • ContainerModel.h: add WorkingDirectory field to ContainerOptions
  • ContainerTasks.cpp: read WorkDir arg and populate options.WorkingDirectory
  • ContainerService.cpp: pass WorkingDirectory when calling exec on the container

Tests

  • CommandLineTestCases.h: parsing cases for --workdir and -w (valid and invalid)
  • WSLCCLIExecutionUnitTests.cpp: 4 unit tests covering:
    • SetContainerOptionsFromArgs sets WorkingDirectory when --workdir is provided
    • SetContainerOptionsFromArgs leaves WorkingDirectory empty when not provided
    • End-to-end parse of --workdir long option sets WorkingDirectory
    • End-to-end parse of -w short alias sets WorkingDirectory

Test plan

  • Build and run unit tests: bin\<platform>\<target>\test.bat /name:*WSLCCLIExecutionUnitTests*
  • Verify wslc exec --workdir /app <container> pwd prints /app
  • Verify wslc exec -w /tmp <container> pwd prints /tmp
  • Verify wslc exec <container> pwd uses the container's default working directory

🤖 Generated with Claude Code

Pooja Trivedi added 2 commits March 30, 2026 13:41
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
@ptrivedi ptrivedi requested a review from a team as a code owner March 30, 2026 19:37
Copilot AI review requested due to automatic review settings March 30, 2026 19:37
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

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 in ContainerExecCommand’s supported arguments.
  • Populate ContainerOptions.WorkingDirectory from parsed args and forward it into WSLCProcessLauncher for 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>
Copilot AI review requested due to automatic review settings March 30, 2026 19:48
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 7 out of 7 changed files in this pull request and generated 1 comment.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 30, 2026 20:56
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 7 out of 7 changed files in this pull request and generated no new comments.

Copy link
Copy Markdown

@AmelBawa-msft AmelBawa-msft left a comment

Choose a reason for hiding this comment

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

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") \
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit: Consider appending WorkDir at the end to preserve the sorted characteristics of the X-macro list

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.

+1 would prefer to keep this list sorted

Copy link
Copy Markdown
Member

@dkbennett dkbennett left a comment

Choose a reason for hiding this comment

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

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)
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.

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") \
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.

+1 would prefer to keep this list sorted

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