-
Notifications
You must be signed in to change notification settings - Fork 1.7k
CLI: Initialize network commands #40313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature/wsl-for-apps
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /*++ | ||
|
|
||
| Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| Module Name: | ||
|
|
||
| NetworkCommand.cpp | ||
|
|
||
| Abstract: | ||
|
|
||
| Implementation of command execution logic. | ||
|
|
||
| --*/ | ||
| #include "CLIExecutionContext.h" | ||
| #include "NetworkCommand.h" | ||
|
|
||
| using namespace wsl::windows::wslc::execution; | ||
| using namespace wsl::shared; | ||
|
|
||
| namespace wsl::windows::wslc { | ||
| // Network Root Command | ||
| std::vector<std::unique_ptr<Command>> NetworkCommand::GetCommands() const | ||
| { | ||
| std::vector<std::unique_ptr<Command>> commands; | ||
| commands.push_back(std::make_unique<NetworkCreateCommand>(FullName())); | ||
| commands.push_back(std::make_unique<NetworkRemoveCommand>(FullName())); | ||
| commands.push_back(std::make_unique<NetworkInspectCommand>(FullName())); | ||
| commands.push_back(std::make_unique<NetworkListCommand>(FullName())); | ||
| return commands; | ||
| } | ||
|
|
||
| std::vector<Argument> NetworkCommand::GetArguments() const | ||
| { | ||
| return {}; | ||
| } | ||
|
|
||
| std::wstring NetworkCommand::ShortDescription() const | ||
| { | ||
| return Localization::WSLCCLI_NetworkCommandDesc(); | ||
| } | ||
|
|
||
| std::wstring NetworkCommand::LongDescription() const | ||
| { | ||
| return Localization::WSLCCLI_NetworkCommandLongDesc(); | ||
| } | ||
|
|
||
| void NetworkCommand::ExecuteInternal(CLIExecutionContext& context) const | ||
| { | ||
| OutputHelp(); | ||
| } | ||
| } // namespace wsl::windows::wslc |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /*++ | ||
|
|
||
| Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| Module Name: | ||
|
|
||
| NetworkCommand.h | ||
|
|
||
| Abstract: | ||
|
|
||
| Declaration of command classes and interfaces. | ||
|
|
||
| --*/ | ||
| #pragma once | ||
| #include "Command.h" | ||
|
|
||
| namespace wsl::windows::wslc { | ||
| // Root Network Command | ||
| struct NetworkCommand final : public Command | ||
| { | ||
| constexpr static std::wstring_view CommandName = L"network"; | ||
| NetworkCommand(const std::wstring& parent) : Command(CommandName, parent) | ||
| { | ||
| } | ||
| std::vector<Argument> GetArguments() const override; | ||
| std::wstring ShortDescription() const override; | ||
| std::wstring LongDescription() const override; | ||
|
|
||
| std::vector<std::unique_ptr<Command>> GetCommands() const override; | ||
|
|
||
| protected: | ||
| void ExecuteInternal(CLIExecutionContext& context) const override; | ||
| }; | ||
|
|
||
| // Create Command | ||
| struct NetworkCreateCommand final : public Command | ||
| { | ||
| constexpr static std::wstring_view CommandName = L"create"; | ||
| NetworkCreateCommand(const std::wstring& parent) : Command(CommandName, parent) | ||
| { | ||
| } | ||
| std::vector<Argument> GetArguments() const override; | ||
| std::wstring ShortDescription() const override; | ||
| std::wstring LongDescription() const override; | ||
|
|
||
| protected: | ||
| void ExecuteInternal(CLIExecutionContext& context) const override; | ||
| }; | ||
|
|
||
| // Remove Command | ||
| struct NetworkRemoveCommand final : public Command | ||
| { | ||
| constexpr static std::wstring_view CommandName = L"remove"; | ||
| NetworkRemoveCommand(const std::wstring& parent) : Command(CommandName, {L"delete", L"rm"}, parent) | ||
| { | ||
| } | ||
| std::vector<Argument> GetArguments() const override; | ||
| std::wstring ShortDescription() const override; | ||
| std::wstring LongDescription() const override; | ||
|
|
||
| protected: | ||
| void ExecuteInternal(CLIExecutionContext& context) const override; | ||
| }; | ||
|
|
||
| // Inspect Command | ||
| struct NetworkInspectCommand final : public Command | ||
| { | ||
| constexpr static std::wstring_view CommandName = L"inspect"; | ||
| NetworkInspectCommand(const std::wstring& parent) : Command(CommandName, parent) | ||
| { | ||
| } | ||
| std::vector<Argument> GetArguments() const override; | ||
| std::wstring ShortDescription() const override; | ||
| std::wstring LongDescription() const override; | ||
|
|
||
| protected: | ||
| void ExecuteInternal(CLIExecutionContext& context) const override; | ||
| }; | ||
|
|
||
| // List Command | ||
| struct NetworkListCommand final : public Command | ||
| { | ||
| constexpr static std::wstring_view CommandName = L"list"; | ||
| NetworkListCommand(const std::wstring& parent) : Command(CommandName, {L"ls"}, parent) | ||
| { | ||
| } | ||
| std::vector<Argument> GetArguments() const override; | ||
| std::wstring ShortDescription() const override; | ||
| std::wstring LongDescription() const override; | ||
|
|
||
| protected: | ||
| void ValidateArgumentsInternal(const ArgMap& execArgs) const override; | ||
| void ExecuteInternal(CLIExecutionContext& context) const override; | ||
| }; | ||
| } // namespace wsl::windows::wslc |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,53 @@ | ||||||||||||||||||||||||||||||||||
| /*++ | ||||||||||||||||||||||||||||||||||
| Copyright (c) Microsoft. All rights reserved. | ||||||||||||||||||||||||||||||||||
| Module Name: | ||||||||||||||||||||||||||||||||||
| NetworkCreateCommand.cpp | ||||||||||||||||||||||||||||||||||
| Abstract: | ||||||||||||||||||||||||||||||||||
| Implementation of command execution logic. | ||||||||||||||||||||||||||||||||||
| --*/ | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| #include "NetworkCommand.h" | ||||||||||||||||||||||||||||||||||
| #include "CLIExecutionContext.h" | ||||||||||||||||||||||||||||||||||
| #include "SessionTasks.h" | ||||||||||||||||||||||||||||||||||
| #include "NetworkTasks.h" | ||||||||||||||||||||||||||||||||||
| #include "Task.h" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| using namespace wsl::windows::wslc::execution; | ||||||||||||||||||||||||||||||||||
| using namespace wsl::windows::wslc::task; | ||||||||||||||||||||||||||||||||||
| using namespace wsl::shared; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| namespace wsl::windows::wslc { | ||||||||||||||||||||||||||||||||||
| // Network Create Command | ||||||||||||||||||||||||||||||||||
| std::vector<Argument> NetworkCreateCommand::GetArguments() const | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||
| Argument::Create(ArgType::NetworkName, true), | ||||||||||||||||||||||||||||||||||
| Argument::Create(ArgType::Driver), | ||||||||||||||||||||||||||||||||||
| Argument::Create(ArgType::Options, false, NO_LIMIT), | ||||||||||||||||||||||||||||||||||
| Argument::Create(ArgType::Label, false, NO_LIMIT), | ||||||||||||||||||||||||||||||||||
|
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), | |
| 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), |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /*++ | ||
|
|
||
| Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| Module Name: | ||
|
|
||
| NetworkInspectCommand.cpp | ||
|
|
||
| Abstract: | ||
|
|
||
| Implementation of command execution logic. | ||
|
|
||
| --*/ | ||
|
|
||
| #include "NetworkCommand.h" | ||
| #include "CLIExecutionContext.h" | ||
| #include "SessionTasks.h" | ||
| #include "NetworkTasks.h" | ||
| #include "Task.h" | ||
|
|
||
| using namespace wsl::windows::wslc::execution; | ||
| using namespace wsl::windows::wslc::task; | ||
| using namespace wsl::shared; | ||
|
|
||
| namespace wsl::windows::wslc { | ||
| // Network Inspect Command | ||
| std::vector<Argument> NetworkInspectCommand::GetArguments() const | ||
| { | ||
| return { | ||
| Argument::Create(ArgType::NetworkName, true, NO_LIMIT), | ||
| Argument::Create(ArgType::Session), | ||
| }; | ||
| } | ||
|
|
||
| std::wstring NetworkInspectCommand::ShortDescription() const | ||
| { | ||
| return Localization::WSLCCLI_NetworkInspectDesc(); | ||
| } | ||
|
|
||
| std::wstring NetworkInspectCommand::LongDescription() const | ||
| { | ||
| return Localization::WSLCCLI_NetworkInspectLongDesc(); | ||
| } | ||
|
|
||
| void NetworkInspectCommand::ExecuteInternal(CLIExecutionContext& context) const | ||
| { | ||
| context << CreateSession // | ||
| << InspectNetworks; | ||
| } | ||
| } // namespace wsl::windows::wslc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
network createtreats--driveras optional, but the underlying COM APIIWSLCSession::CreateNetworkrequiresWSLCNetworkOptions::Driverto 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--driverrequired for this command or supply a default (likely "bridge") before calling into the service, and update help text accordingly.