Skip to content

Refactor IsContainerNetworkMode into ParseContainerNetworkMode#40606

Merged
beena352 merged 3 commits into
microsoft:masterfrom
beena352:user/beenachauhan/parse-container-network-mode
May 21, 2026
Merged

Refactor IsContainerNetworkMode into ParseContainerNetworkMode#40606
beena352 merged 3 commits into
microsoft:masterfrom
beena352:user/beenachauhan/parse-container-network-mode

Conversation

@beena352
Copy link
Copy Markdown
Contributor

Summary of the Pull Request

Replaces the IsContainerNetworkMode boolean helper with ParseContainerNetworkMode which returns the parsed target name directly. This eliminates duplicated prefix+substr+validate logic that was hand-rolled in multiple places.

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

This is a followup PR to #40601 addressing review comment to consolidate the container network mode parsing logic.
The container:<name|id> prefix parsing was done in two different ways:

  • IsContainerNetworkMode() check followed by manual substr()
  • Direct starts_with() + substr() without using the helper at all
    ParseContainerNetworkMode consolidates both patterns into a single function that returns std::optionalstd::string - the target name if the mode matches, std::nullopt otherwise. Two overloads are provided: one for LPCSTR (user-input paths) and one for std::string_view (Docker inspect recovery path).

Validation Steps Performed

Copilot AI review requested due to automatic review settings May 20, 2026 16:13
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

Note

Copilot was unable to run its full agentic suite in this review.

Refactors container network mode handling by replacing a boolean IsContainerNetworkMode helper with ParseContainerNetworkMode, which parses and returns the container target identifier as an std::optional<std::string>.

Changes:

  • Added ParseContainerNetworkMode overloads for LPCSTR and std::string_view.
  • Updated call sites to use the new parser and removed manual prefix/substr parsing.
  • Switched container-mode checks in a few places from boolean helper usage to optional presence checks.

Comment thread src/windows/wslcsession/WSLCContainer.cpp Outdated
Comment thread src/windows/wslcsession/WSLCContainer.cpp Outdated
Comment thread src/windows/wslcsession/WSLCContainer.cpp Outdated
Comment thread src/windows/wslcsession/WSLCContainer.cpp Outdated
@beena352 beena352 requested a review from Copilot May 20, 2026 16:39
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 1 out of 1 changed files in this pull request and generated 2 comments.

Comment thread src/windows/wslcsession/WSLCContainer.cpp Outdated
Comment thread src/windows/wslcsession/WSLCContainer.cpp Outdated
@beena352 beena352 marked this pull request as ready for review May 20, 2026 17:08
@beena352 beena352 requested a review from a team as a code owner May 20, 2026 17:08
Comment thread src/windows/wslcsession/WSLCContainer.cpp Outdated
Comment thread src/windows/wslcsession/WSLCContainer.cpp Outdated
Comment thread src/windows/wslcsession/WSLCContainer.cpp
@kvega005
Copy link
Copy Markdown
Contributor

LGTM

@kvega005 kvega005 self-requested a review May 21, 2026 00:31
@beena352 beena352 merged commit 91ada0b into microsoft:master May 21, 2026
9 checks passed
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.

3 participants