MCPcopy Create free account
hub / github.com/Mixaill/FakePDB / Main

Class Main

src_cpp/src/main.cpp:24–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22
23namespace FakePDB {
24 class Main {
25 public:
26 void AddCommand(std::shared_ptr<CommandInterface> i) {
27 _commands.push_back(i);
28 }
29
30 int Run(int argc, char* argv[]) {
31 if (argc < 2) {
32 Usage();
33 return 0;
34 }
35
36 std::string command_name = argv[1];
37 for (auto& command : _commands) {
38 //check name
39 if (command->GetCommandName() != command_name) {
40 continue;
41 }
42
43 //check arg count
44 if (argc-2 < command->GetArgsMin() || argc-2 > command->GetArgsMax()) {
45 std::cerr << "Invalid number of arguments" << std::endl;
46 for (auto& usage : command->GetCommandUsage()) {
47 std::cout << "Usage : " << command->GetCommandName() << " " << usage << std::endl;
48 }
49 }
50
51 //run
52 return command->Run(argc, argv);
53 }
54
55 std::cerr << "Command not found" << std::endl;
56 Usage();
57 return 1;
58 }
59
60 void Usage() {
61 std::cout << "Available commands" << std::endl << std::endl;
62
63 for (auto& command : _commands) {
64 std::cout << "Name : " << command->GetCommandName() << std::endl;
65 std::cout << "Description: " << command->GetCommandDescription() << std::endl;
66 for (auto& usage : command->GetCommandUsage()) {
67 std::cout << "Usage : " << command->GetCommandName() << " " << usage << std::endl;
68 }
69
70 std::cout << std::endl;
71 }
72 }
73
74 private:
75 std::vector<std::shared_ptr<CommandInterface>> _commands;
76 };
77}
78
79

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected