CLI: Initialize network commands#40313
CLI: Initialize network commands#40313AmelBawa-msft wants to merge 3 commits intofeature/wsl-for-appsfrom
Conversation
There was a problem hiding this comment.
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 networkroot command withcreate/remove/inspect/listsubcommands wired through tasks and aNetworkService. - Extends
inspectto support--type networkand 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. |
| return { | ||
| Argument::Create(ArgType::NetworkName, true), | ||
| Argument::Create(ArgType::Driver), | ||
| Argument::Create(ArgType::Options, false, NO_LIMIT), | ||
| Argument::Create(ArgType::Label, false, NO_LIMIT), |
There was a problem hiding this comment.
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.
| 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), |
| { | ||
| return { | ||
| Argument::Create(ArgType::NetworkName, true), | ||
| Argument::Create(ArgType::Driver), |
There was a problem hiding this comment.
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.
| Argument::Create(ArgType::Driver), | |
| Argument::Create(ArgType::Driver, true), |
| if (context.Args.Contains(ArgType::Driver)) | ||
| { | ||
| options.Driver = WideToMultiByte(context.Args.Get<ArgType::Driver>()); | ||
| } |
There was a problem hiding this comment.
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.
| } | |
| } | |
| else | |
| { | |
| options.Driver = "bridge"; | |
| } |
| << 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" // |
There was a problem hiding this comment.
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).
| << 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" // |
|
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. |
Summary of the Pull Request
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed