Skip to content

CLI: Initialize network commands#40313

Draft
AmelBawa-msft wants to merge 3 commits intofeature/wsl-for-appsfrom
user/amelbawa/network
Draft

CLI: Initialize network commands#40313
AmelBawa-msft wants to merge 3 commits intofeature/wsl-for-appsfrom
user/amelbawa/network

Conversation

@AmelBawa-msft
Copy link
Copy Markdown

@AmelBawa-msft AmelBawa-msft commented Apr 24, 2026

Summary of the Pull Request

  • Added wslc network command group with create, remove, inspect, and list subcommands
  • network create supports --driver, --opt (driver options), and --label flags, forwarding them to IWSLCSession::CreateNetwork.
  • network list supports --format (table/json) and --quiet output modes.
  • network inspect and network remove accept multiple network names, handle not-found errors gracefully (print friendly message, set exit code 1, continue processing remaining items).
  • Integrated networks into the generic inspect command so wslc inspect --type network also works.
  • Comprehensive E2E tests for all four subcommands plus the generic inspect path.

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

Copilot AI review requested due to automatic review settings April 24, 2026 20:04
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 initial WSLC CLI support for managing networks (wslc network ...) and extends wslc inspect to understand the new network object type, alongside end-to-end coverage and required schema/localization plumbing.

Changes:

  • Introduces wslc network root command with create/remove/inspect/list subcommands wired through tasks and a NetworkService.
  • Extends inspect to support --type network and updates resolution priority (image > network > volume).
  • Adds e2e tests, JSON serialization for WSLCNetworkInformation, and localized CLI strings for network commands.

Reviewed changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/windows/wslc/e2e/WSLCE2ENetworkTests.cpp Adds e2e coverage for wslc network root help / invalid subcommand behavior.
test/windows/wslc/e2e/WSLCE2ENetworkCreateTests.cpp Adds e2e coverage for network create (help/success/labels/invalid driver/duplicate).
test/windows/wslc/e2e/WSLCE2ENetworkRemoveTests.cpp Adds e2e coverage for network remove (help/valid/multiple/not found/mixed).
test/windows/wslc/e2e/WSLCE2ENetworkInspectTests.cpp Adds e2e coverage for network inspect (help/success/multiple/not found/mixed).
test/windows/wslc/e2e/WSLCE2ENetworkListTests.cpp Adds e2e coverage for network list (help/format validation/quiet/json).
test/windows/wslc/e2e/WSLCE2EInspectTests.cpp Updates inspect e2e tests for network type + priority rules.
test/windows/wslc/e2e/WSLCE2EHelpers.h Adds helper declarations for network list/inspect/cleanup.
test/windows/wslc/e2e/WSLCE2EHelpers.cpp Implements network helpers using wslc network list/inspect/rm.
test/windows/wslc/e2e/WSLCE2EGlobalTests.cpp Ensures global help includes the new network command.
src/windows/wslc/commands/RootCommand.cpp Registers NetworkCommand under the root command.
src/windows/wslc/commands/NetworkCommand.h Declares the network command + subcommand classes.
src/windows/wslc/commands/NetworkCommand.cpp Implements network root command wiring and help behavior.
src/windows/wslc/commands/NetworkCreateCommand.cpp Implements network create command argument set + execution pipeline.
src/windows/wslc/commands/NetworkRemoveCommand.cpp Implements network remove command argument set + execution pipeline.
src/windows/wslc/commands/NetworkInspectCommand.cpp Implements network inspect command argument set + execution pipeline.
src/windows/wslc/commands/NetworkListCommand.cpp Implements network list command arguments + format validation + execution pipeline.
src/windows/wslc/tasks/NetworkTasks.h Declares network task functions used by the command pipelines.
src/windows/wslc/tasks/NetworkTasks.cpp Implements network task logic (create/delete/list/inspect/json/table output).
src/windows/wslc/services/NetworkModel.h Adds network create options model.
src/windows/wslc/services/NetworkService.h Declares NetworkService interface for COM calls.
src/windows/wslc/services/NetworkService.cpp Implements network create/delete/list/inspect via IWSLCSession.
src/windows/wslc/tasks/InspectTasks.cpp Adds network inspection support to generic inspect task.
src/windows/wslc/services/InspectModel.h Extends inspect type flags to include Network.
src/windows/wslc/core/ExecutionContextData.h Adds Data::Networks storage for list pipelines.
src/windows/wslc/arguments/ArgumentDefinitions.h Adds positional network-name argument definition.
src/windows/wslc/arguments/ArgumentValidation.cpp Accepts --type network and updates supported-values list.
src/shared/inc/JsonUtils.h Adds JSON (de)serialization for WSLCNetworkInformation.
localization/strings/en-US/Resources.resw Adds localized strings for network commands and arguments.

Comment on lines +29 to +33
return {
Argument::Create(ArgType::NetworkName, true),
Argument::Create(ArgType::Driver),
Argument::Create(ArgType::Options, false, NO_LIMIT),
Argument::Create(ArgType::Label, false, NO_LIMIT),
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

NetworkCreateCommand reuses shared --driver/--label argument definitions whose descriptions are volume-specific (e.g., DriverArgDescription("guest") and "Volume metadata setting"). This makes wslc network create --help misleading. Consider overriding these descriptions for the network command (and localizing them) so help text refers to network drivers/labels and reflects the actual default/supported driver values.

Suggested change
return {
Argument::Create(ArgType::NetworkName, true),
Argument::Create(ArgType::Driver),
Argument::Create(ArgType::Options, false, NO_LIMIT),
Argument::Create(ArgType::Label, false, NO_LIMIT),
auto driverArgument = Argument::Create(ArgType::Driver);
driverArgument.Description = Localization::WSLCCLI_NetworkCreateDriverArgDesc();
auto labelArgument = Argument::Create(ArgType::Label, false, NO_LIMIT);
labelArgument.Description = Localization::WSLCCLI_NetworkCreateLabelArgDesc();
return {
Argument::Create(ArgType::NetworkName, true),
std::move(driverArgument),
Argument::Create(ArgType::Options, false, NO_LIMIT),
std::move(labelArgument),

Copilot uses AI. Check for mistakes.
{
return {
Argument::Create(ArgType::NetworkName, true),
Argument::Create(ArgType::Driver),
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

network create treats --driver as optional, but the underlying COM API IWSLCSession::CreateNetwork requires WSLCNetworkOptions::Driver to be non-null. If the user omits --driver, the CLI will pass a null driver and fail with an internal pointer error instead of a user-friendly message. Please either make --driver required for this command or supply a default (likely "bridge") before calling into the service, and update help text accordingly.

Suggested change
Argument::Create(ArgType::Driver),
Argument::Create(ArgType::Driver, true),

Copilot uses AI. Check for mistakes.
if (context.Args.Contains(ArgType::Driver))
{
options.Driver = WideToMultiByte(context.Args.Get<ArgType::Driver>());
}
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

CreateNetworkOptions::Driver is only populated when --driver is provided, but NetworkService::Create forwards the driver pointer directly into IWSLCSession::CreateNetwork, which requires a non-null driver. Add a default (e.g., "bridge") or validate and emit a clear user error when the driver argument is missing, instead of allowing a null driver to flow into the COM call.

Suggested change
}
}
else
{
options.Driver = "bridge";
}

Copilot uses AI. Check for mistakes.
Comment on lines +134 to +136
<< L" -d,--driver Specify volume driver name (default guest)\r\n" //
<< L" -o,--opt Set driver specific options\r\n" //
<< L" --label Volume metadata setting\r\n" //
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

The expected help text for network create lists volume-specific option descriptions (e.g., "Specify volume driver name" and "Volume metadata setting"). Since this command is user-facing, the help output (and therefore this test expectation) should use network-appropriate, localized descriptions (and the driver default should reflect actual behavior, e.g., defaulting to "bridge" if implemented).

Suggested change
<< L" -d,--driver Specify volume driver name (default guest)\r\n" //
<< L" -o,--opt Set driver specific options\r\n" //
<< L" --label Volume metadata setting\r\n" //
<< L" -d,--driver Specify network driver name (default bridge)\r\n" //
<< L" -o,--opt Set driver specific options\r\n" //
<< L" --label Network metadata setting\r\n" //

Copilot uses AI. Check for mistakes.
@benhillis
Copy link
Copy Markdown
Member

benhillis commented Apr 25, 2026

Iin NetworkService::Create local vectors for driverOpts/labels go out of scope after their .data() pointers are stored in WSLCNetworkOptions. Works today because the COM method copies immediately, but it is fragile. Also CreateNetwork has no out param unlike CreateVolume, so you are printing the input name instead of the API response.

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