master
cpp 116 lines 4.37 KB
Raw
1 /*++
2
3 Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 RootCommand.cpp
8
9 Abstract:
10
11 Implementation of the RootCommand, which is the root of all commands in the CLI.
12
13 --*/
14 #include "RootCommand.h"
15
16 // Include all commands that parent to the root.
17 #include "ContainerCommand.h"
18 #include "ImageCommand.h"
19 #include "NetworkCommand.h"
20 #include "RegistryCommand.h"
21 #include "SettingsCommand.h"
22 #include "SystemCommand.h"
23 #include "InspectCommand.h"
24 #include "VersionCommand.h"
25 #include "VolumeCommand.h"
26
27 using namespace wsl::windows::wslc::execution;
28 using namespace wsl::shared;
29
30 namespace wsl::windows::wslc {
31 std::vector<std::unique_ptr<Command>> RootCommand::GetCommands() const
32 {
33 std::vector<std::unique_ptr<Command>> commands;
34 commands.push_back(std::make_unique<ContainerCommand>(FullName()));
35 commands.push_back(std::make_unique<ImageCommand>(FullName()));
36 commands.push_back(std::make_unique<NetworkCommand>(FullName()));
37 commands.push_back(std::make_unique<RegistryCommand>(FullName()));
38 commands.push_back(std::make_unique<SettingsCommand>(FullName()));
39 commands.push_back(std::make_unique<SystemCommand>(FullName()));
40 commands.push_back(std::make_unique<VolumeCommand>(FullName()));
41 commands.push_back(std::make_unique<ContainerAttachCommand>(FullName()));
42 commands.push_back(std::make_unique<ImageBuildCommand>(FullName()));
43 commands.push_back(std::make_unique<ContainerCreateCommand>(FullName()));
44 commands.push_back(std::make_unique<ContainerExecCommand>(FullName()));
45 commands.push_back(std::make_unique<ContainerExportCommand>(FullName()));
46 commands.push_back(std::make_unique<ImageListCommand>(FullName(), true));
47 commands.push_back(std::make_unique<ImageImportCommand>(FullName()));
48 commands.push_back(std::make_unique<SystemInfoCommand>(FullName()));
49 commands.push_back(std::make_unique<InspectCommand>(FullName()));
50 commands.push_back(std::make_unique<ContainerKillCommand>(FullName()));
51 commands.push_back(std::make_unique<ContainerListCommand>(FullName()));
52 commands.push_back(std::make_unique<ImageLoadCommand>(FullName()));
53 commands.push_back(std::make_unique<RegistryLoginCommand>(FullName()));
54 commands.push_back(std::make_unique<RegistryLogoutCommand>(FullName()));
55 commands.push_back(std::make_unique<ContainerLogsCommand>(FullName()));
56 commands.push_back(std::make_unique<ImagePullCommand>(FullName()));
57 commands.push_back(std::make_unique<ImagePushCommand>(FullName()));
58 commands.push_back(std::make_unique<ContainerRemoveCommand>(FullName()));
59 commands.push_back(std::make_unique<ContainerRestartCommand>(FullName()));
60 commands.push_back(std::make_unique<ImageRemoveCommand>(FullName(), true));
61 commands.push_back(std::make_unique<ContainerRunCommand>(FullName()));
62 commands.push_back(std::make_unique<ImageSaveCommand>(FullName()));
63 commands.push_back(std::make_unique<ContainerStartCommand>(FullName()));
64 commands.push_back(std::make_unique<ContainerStatsCommand>(FullName()));
65 commands.push_back(std::make_unique<ContainerStopCommand>(FullName()));
66 commands.push_back(std::make_unique<ImageTagCommand>(FullName()));
67 commands.push_back(std::make_unique<VersionCommand>(FullName()));
68 return commands;
69 }
70
71 std::vector<Argument> RootCommand::GetArguments() const
72 {
73 return {
74 Argument::Create(ArgType::Version),
75 };
76 }
77
78 // Global options apply to the overall invocation and may appear before any
79 // subcommand (e.g. `wslc --session foo image list`). Define them here using
80 // the Argument::Create factory backed by ArgumentDefinitions.h so help text,
81 // aliases, validation, and parsing match subcommand arguments.
82 std::vector<Argument> RootCommand::GetGlobalArguments() const
83 {
84 return {
85 Argument::Create(ArgType::Session),
86 };
87 }
88
89 std::vector<Argument> RootCommand::GetEnvArguments() const
90 {
91 return {
92 Argument::Create(ArgType::NoColor),
93 };
94 }
95
96 std::wstring RootCommand::ShortDescription() const
97 {
98 return Localization::WSLCCLI_RootCommandDesc();
99 }
100
101 std::wstring RootCommand::LongDescription() const
102 {
103 return Localization::WSLCCLI_RootCommandLongDesc();
104 }
105
106 void RootCommand::ExecuteInternal(CLIExecutionContext& context) const
107 {
108 if (context.Args.GetValue<ArgType::Version>())
109 {
110 VersionCommand::PrintVersion(context.Terminal);
111 return;
112 }
113
114 OutputHelp(context.Terminal);
115 }
116 } // namespace wsl::windows::wslc