| 1 | /*++ |
| 2 | |
| 3 | Copyright (c) Microsoft. All rights reserved. |
| 4 | |
| 5 | Module Name: |
| 6 | |
| 7 | ContainerCommand.h |
| 8 | |
| 9 | Abstract: |
| 10 | |
| 11 | Declaration of command classes and interfaces. |
| 12 | |
| 13 | --*/ |
| 14 | #pragma once |
| 15 | #include "Command.h" |
| 16 | |
| 17 | namespace wsl::windows::wslc { |
| 18 | // Root Container Command |
| 19 | struct ContainerCommand final : public Command |
| 20 | { |
| 21 | constexpr static std::wstring_view CommandName = L"container"; |
| 22 | ContainerCommand(const std::wstring& parent) : Command(CommandName, parent) |
| 23 | { |
| 24 | } |
| 25 | std::vector<Argument> GetArguments() const override; |
| 26 | std::wstring ShortDescription() const override; |
| 27 | std::wstring LongDescription() const override; |
| 28 | |
| 29 | std::vector<std::unique_ptr<Command>> GetCommands() const override; |
| 30 | |
| 31 | protected: |
| 32 | void ExecuteInternal(CLIExecutionContext& context) const override; |
| 33 | }; |
| 34 | |
| 35 | // Attach Command |
| 36 | struct ContainerAttachCommand final : public Command |
| 37 | { |
| 38 | constexpr static std::wstring_view CommandName = L"attach"; |
| 39 | ContainerAttachCommand(const std::wstring& parent) : Command(CommandName, parent) |
| 40 | { |
| 41 | } |
| 42 | std::vector<Argument> GetArguments() const override; |
| 43 | std::wstring ShortDescription() const override; |
| 44 | std::wstring LongDescription() const override; |
| 45 | |
| 46 | protected: |
| 47 | void ExecuteInternal(CLIExecutionContext& context) const override; |
| 48 | }; |
| 49 | |
| 50 | // Create Command |
| 51 | struct ContainerCreateCommand final : public Command |
| 52 | { |
| 53 | constexpr static std::wstring_view CommandName = L"create"; |
| 54 | ContainerCreateCommand(const std::wstring& parent) : Command(CommandName, parent) |
| 55 | { |
| 56 | } |
| 57 | std::vector<Argument> GetArguments() const override; |
| 58 | std::wstring ShortDescription() const override; |
| 59 | std::wstring LongDescription() const override; |
| 60 | |
| 61 | protected: |
| 62 | void ExecuteInternal(CLIExecutionContext& context) const override; |
| 63 | }; |
| 64 | |
| 65 | // Cp Command |
| 66 | struct ContainerCpCommand final : public Command |
| 67 | { |
| 68 | constexpr static std::wstring_view CommandName = L"cp"; |
| 69 | ContainerCpCommand(const std::wstring& parent) : Command(CommandName, parent) |
| 70 | { |
| 71 | } |
| 72 | std::vector<Argument> GetArguments() const override; |
| 73 | std::wstring ShortDescription() const override; |
| 74 | std::wstring LongDescription() const override; |
| 75 | |
| 76 | protected: |
| 77 | void ExecuteInternal(CLIExecutionContext& context) const override; |
| 78 | }; |
| 79 | |
| 80 | // Exec Command |
| 81 | struct ContainerExecCommand final : public Command |
| 82 | { |
| 83 | constexpr static std::wstring_view CommandName = L"exec"; |
| 84 | ContainerExecCommand(const std::wstring& parent) : Command(CommandName, parent) |
| 85 | { |
| 86 | } |
| 87 | std::vector<Argument> GetArguments() const override; |
| 88 | std::wstring ShortDescription() const override; |
| 89 | std::wstring LongDescription() const override; |
| 90 | |
| 91 | protected: |
| 92 | void ExecuteInternal(CLIExecutionContext& context) const override; |
| 93 | }; |
| 94 | |
| 95 | // Export Command |
| 96 | struct ContainerExportCommand final : public Command |
| 97 | { |
| 98 | constexpr static std::wstring_view CommandName = L"export"; |
| 99 | ContainerExportCommand(const std::wstring& parent) : Command(CommandName, parent) |
| 100 | { |
| 101 | } |
| 102 | std::vector<Argument> GetArguments() const override; |
| 103 | std::wstring ShortDescription() const override; |
| 104 | std::wstring LongDescription() const override; |
| 105 | |
| 106 | protected: |
| 107 | void ExecuteInternal(CLIExecutionContext& context) const override; |
| 108 | }; |
| 109 | |
| 110 | // Inspect Command |
| 111 | struct ContainerInspectCommand final : public Command |
| 112 | { |
| 113 | constexpr static std::wstring_view CommandName = L"inspect"; |
| 114 | ContainerInspectCommand(const std::wstring& parent) : Command(CommandName, parent) |
| 115 | { |
| 116 | } |
| 117 | std::vector<Argument> GetArguments() const override; |
| 118 | std::wstring ShortDescription() const override; |
| 119 | std::wstring LongDescription() const override; |
| 120 | |
| 121 | protected: |
| 122 | void ExecuteInternal(CLIExecutionContext& context) const override; |
| 123 | }; |
| 124 | |
| 125 | // Kill Command |
| 126 | struct ContainerKillCommand final : public Command |
| 127 | { |
| 128 | constexpr static std::wstring_view CommandName = L"kill"; |
| 129 | ContainerKillCommand(const std::wstring& parent) : Command(CommandName, parent) |
| 130 | { |
| 131 | } |
| 132 | std::vector<Argument> GetArguments() const override; |
| 133 | std::wstring ShortDescription() const override; |
| 134 | std::wstring LongDescription() const override; |
| 135 | |
| 136 | protected: |
| 137 | void ExecuteInternal(CLIExecutionContext& context) const override; |
| 138 | }; |
| 139 | |
| 140 | // List Command |
| 141 | struct ContainerListCommand final : public Command |
| 142 | { |
| 143 | constexpr static std::wstring_view CommandName = L"list"; |
| 144 | ContainerListCommand(const std::wstring& parent) : Command(CommandName, {L"ls", L"ps"}, parent) |
| 145 | { |
| 146 | } |
| 147 | std::vector<Argument> GetArguments() const override; |
| 148 | std::wstring ShortDescription() const override; |
| 149 | std::wstring LongDescription() const override; |
| 150 | |
| 151 | protected: |
| 152 | void ExecuteInternal(CLIExecutionContext& context) const override; |
| 153 | void ValidateArgumentsInternal(ArgMap& execArgs) const override; |
| 154 | }; |
| 155 | |
| 156 | // Logs Command |
| 157 | struct ContainerLogsCommand final : public Command |
| 158 | { |
| 159 | constexpr static std::wstring_view CommandName = L"logs"; |
| 160 | ContainerLogsCommand(const std::wstring& parent) : Command(CommandName, parent) |
| 161 | { |
| 162 | } |
| 163 | std::vector<Argument> GetArguments() const override; |
| 164 | std::wstring ShortDescription() const override; |
| 165 | std::wstring LongDescription() const override; |
| 166 | |
| 167 | protected: |
| 168 | void ExecuteInternal(CLIExecutionContext& context) const override; |
| 169 | }; |
| 170 | |
| 171 | // Remove Command |
| 172 | struct ContainerRemoveCommand final : public Command |
| 173 | { |
| 174 | constexpr static std::wstring_view CommandName = L"remove"; |
| 175 | ContainerRemoveCommand(const std::wstring& parent) : Command(CommandName, {L"delete", L"rm"}, parent) |
| 176 | { |
| 177 | } |
| 178 | std::vector<Argument> GetArguments() const override; |
| 179 | std::wstring ShortDescription() const override; |
| 180 | std::wstring LongDescription() const override; |
| 181 | |
| 182 | protected: |
| 183 | void ExecuteInternal(CLIExecutionContext& context) const override; |
| 184 | }; |
| 185 | |
| 186 | // Restart Command |
| 187 | struct ContainerRestartCommand final : public Command |
| 188 | { |
| 189 | constexpr static std::wstring_view CommandName = L"restart"; |
| 190 | ContainerRestartCommand(const std::wstring& parent) : Command(CommandName, parent) |
| 191 | { |
| 192 | } |
| 193 | std::vector<Argument> GetArguments() const override; |
| 194 | std::wstring ShortDescription() const override; |
| 195 | std::wstring LongDescription() const override; |
| 196 | |
| 197 | protected: |
| 198 | void ExecuteInternal(CLIExecutionContext& context) const override; |
| 199 | }; |
| 200 | |
| 201 | // Run Command |
| 202 | struct ContainerRunCommand final : public Command |
| 203 | { |
| 204 | constexpr static std::wstring_view CommandName = L"run"; |
| 205 | ContainerRunCommand(const std::wstring& parent) : Command(CommandName, parent) |
| 206 | { |
| 207 | } |
| 208 | std::vector<Argument> GetArguments() const override; |
| 209 | std::wstring ShortDescription() const override; |
| 210 | std::wstring LongDescription() const override; |
| 211 | |
| 212 | protected: |
| 213 | void ExecuteInternal(CLIExecutionContext& context) const override; |
| 214 | }; |
| 215 | |
| 216 | // Start Command |
| 217 | struct ContainerStartCommand final : public Command |
| 218 | { |
| 219 | constexpr static std::wstring_view CommandName = L"start"; |
| 220 | ContainerStartCommand(const std::wstring& parent) : Command(CommandName, parent) |
| 221 | { |
| 222 | } |
| 223 | std::vector<Argument> GetArguments() const override; |
| 224 | std::wstring ShortDescription() const override; |
| 225 | std::wstring LongDescription() const override; |
| 226 | |
| 227 | protected: |
| 228 | void ExecuteInternal(CLIExecutionContext& context) const override; |
| 229 | }; |
| 230 | |
| 231 | // Stats Command |
| 232 | struct ContainerStatsCommand final : public Command |
| 233 | { |
| 234 | constexpr static std::wstring_view CommandName = L"stats"; |
| 235 | ContainerStatsCommand(const std::wstring& parent) : Command(CommandName, parent) |
| 236 | { |
| 237 | } |
| 238 | std::vector<Argument> GetArguments() const override; |
| 239 | std::wstring ShortDescription() const override; |
| 240 | std::wstring LongDescription() const override; |
| 241 | |
| 242 | protected: |
| 243 | void ExecuteInternal(CLIExecutionContext& context) const override; |
| 244 | }; |
| 245 | |
| 246 | // Stop Command |
| 247 | struct ContainerStopCommand final : public Command |
| 248 | { |
| 249 | constexpr static std::wstring_view CommandName = L"stop"; |
| 250 | ContainerStopCommand(const std::wstring& parent) : Command(CommandName, parent) |
| 251 | { |
| 252 | } |
| 253 | std::vector<Argument> GetArguments() const override; |
| 254 | std::wstring ShortDescription() const override; |
| 255 | std::wstring LongDescription() const override; |
| 256 | |
| 257 | protected: |
| 258 | void ExecuteInternal(CLIExecutionContext& context) const override; |
| 259 | }; |
| 260 | |
| 261 | // Prune Command |
| 262 | struct ContainerPruneCommand final : public Command |
| 263 | { |
| 264 | constexpr static std::wstring_view CommandName = L"prune"; |
| 265 | ContainerPruneCommand(const std::wstring& parent) : Command(CommandName, parent) |
| 266 | { |
| 267 | } |
| 268 | std::vector<Argument> GetArguments() const override; |
| 269 | std::wstring ShortDescription() const override; |
| 270 | std::wstring LongDescription() const override; |
| 271 | |
| 272 | protected: |
| 273 | void ExecuteInternal(CLIExecutionContext& context) const override; |
| 274 | }; |
| 275 | } // namespace wsl::windows::wslc |