Skip to content

CLI: Make image save output optional#40194

Open
AmelBawa-msft wants to merge 4 commits intofeature/wsl-for-appsfrom
user/amelbawa/image-save-output
Open

CLI: Make image save output optional#40194
AmelBawa-msft wants to merge 4 commits intofeature/wsl-for-appsfrom
user/amelbawa/image-save-output

Conversation

@AmelBawa-msft
Copy link
Copy Markdown

Summary of the Pull Request

  • Make image save output optional
wslc image save debian:latest > ./Debian.tar

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

@AmelBawa-msft AmelBawa-msft requested a review from a team as a code owner April 15, 2026 21:39
Copilot AI review requested due to automatic review settings April 15, 2026 21:39
@AmelBawa-msft AmelBawa-msft changed the title Make image save output optional CLI: Make image save output optional Apr 15, 2026
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 wslc image save to write the image archive to stdout when --output/-o is omitted, enabling shell redirection scenarios (while blocking direct writes to an interactive terminal).

Changes:

  • Make image save’s --output argument optional and route output to stdout when omitted.
  • Add a terminal-safety check to reject saving directly to an interactive console without redirection.
  • Extend E2E test coverage to validate stdout-save success and terminal-save failure.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/windows/wslc/e2e/WSLCExecutor.h Declares a new test helper to run wslc with stdout optionally redirected to a file.
test/windows/wslc/e2e/WSLCExecutor.cpp Implements the redirecting helper used by new stdout-save tests.
test/windows/wslc/e2e/WSLCE2EImageSaveTests.cpp Updates tests for optional output, adds stdout-save and terminal-failure scenarios.
src/windows/wslc/tasks/ImageTasks.cpp Implements image save behavior: use --output if provided, otherwise write to stdout (with terminal guard).
src/windows/wslc/services/ImageService.h Adds an overload to save to a provided output HANDLE.
src/windows/wslc/services/ImageService.cpp Implements the new handle-based save overload and reuses it from the path-based save.
src/windows/wslc/commands/ImageSaveCommand.cpp Makes the --output argument optional at the command-definition level.
localization/strings/en-US/Resources.resw Adds a localized user-facing error string for “stdout is a terminal” rejection.

Comment thread test/windows/wslc/e2e/WSLCE2EImageSaveTests.cpp Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 15, 2026 21:57
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 8 out of 8 changed files in this pull request and generated 4 comments.

Comment thread localization/strings/en-US/Resources.resw
Comment thread test/windows/wslc/e2e/WSLCE2EImageSaveTests.cpp Outdated
Comment thread test/windows/wslc/e2e/WSLCE2EImageSaveTests.cpp
Comment thread test/windows/wslc/e2e/WSLCExecutor.cpp Outdated
Comment thread test/windows/wslc/e2e/WSLCExecutor.cpp
- Open CONOUT$ as child stdout in RunWslcAndRedirectToFile when no output
  path is given, so IsConsoleHandle() returns true in the child process
  regardless of how CI redirects the test runner's stdout
- Fix SavedArchivePath.wstring() -> SavedArchivePath in WSLCE2E_Image_Save_ToStdout_Load
- Quote output path in effectiveCommandLine for diagnostic clarity

Agent-Logs-Url: https://github.com/microsoft/WSL/sessions/f94556e1-9acd-40f1-89bd-349e238e92f3

Co-authored-by: AmelBawa-msft <104940545+AmelBawa-msft@users.noreply.github.com>
}
else
{
// Open CONOUT$ so the child process receives a real console handle regardless of
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.

That's clever ! I think this should be OK in most cases, but this might fail if the tests are run in a console-less context.

If that happens, we can always revisit

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