11 #include "CLI.h" |
11 #include "CLI.h" |
12 #include "Command.h" |
12 #include "Command.h" |
13 #include "ArgumentsCommand.h" |
13 #include "ArgumentsCommand.h" |
14 #include "DemoCommand.h" |
14 #include "DemoCommand.h" |
15 |
15 |
|
16 using namespace relpipe::cli; |
|
17 using namespace relpipe::in::cli; |
|
18 using namespace relpipe::writer; |
|
19 |
|
20 Command* findCommand(string_t commandName) { |
|
21 if (commandName == L"demo") return new DemoCommand(); |
|
22 else if (commandName == L"generate") return new ArgumentsCommand(); |
|
23 else throw new RelpipeWriterException(L"Unknown command: " + commandName); // TODO: CLI expcetion |
|
24 } |
|
25 |
16 int main(int argc, char** argv) { |
26 int main(int argc, char** argv) { |
17 using namespace relpipe::cli; |
|
18 using namespace relpipe::in::cli; |
|
19 using namespace relpipe::writer; |
|
20 |
|
21 setlocale(LC_ALL, ""); |
27 setlocale(LC_ALL, ""); |
22 CLI cli(argc, argv); |
28 CLI cli(argc, argv); |
23 |
29 |
24 int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
30 int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
25 |
31 |
26 try { |
32 try { |
27 if (cli.arguments().size() > 0) { |
33 if (cli.arguments().size() > 0) { |
28 |
34 |
29 const wstring action = cli.arguments()[0]; |
35 const wstring commandName = cli.arguments()[0]; |
30 vector<wstring> arguments(cli.arguments().size() - 1); |
36 vector<wstring> arguments(cli.arguments().size() - 1); |
31 for (int i = 1; i < cli.arguments().size(); i++) { |
37 for (int i = 1; i < cli.arguments().size(); i++) { |
32 arguments[i - 1] = cli.arguments()[i]; |
38 arguments[i - 1] = cli.arguments()[i]; |
33 } |
39 } |
34 |
40 |
35 if (action == L"demo") { |
41 std::shared_ptr<Command> command(findCommand(commandName)); |
36 DemoCommand command; |
42 command->process(cin, cout, commandName, arguments); |
37 command.process(cin, cout, action, arguments); |
43 resultCode = CLI::EXIT_CODE_SUCCESS; |
38 resultCode = CLI::EXIT_CODE_SUCCESS; |
|
39 } else if (action == L"generate") { |
|
40 ArgumentsCommand command; |
|
41 command.process(cin, cout, action, arguments); |
|
42 resultCode = CLI::EXIT_CODE_SUCCESS; |
|
43 } else { |
|
44 fwprintf(stderr, L"Unknown command: %ls\n", action.c_str()); |
|
45 resultCode = CLI::EXIT_CODE_UNKNOWN_COMMAND; |
|
46 } |
|
47 |
|
48 |
44 |
49 } else { |
45 } else { |
50 fwprintf(stderr, L"Missing command…\n"); |
46 fwprintf(stderr, L"Missing command…\n"); |
51 resultCode = CLI::EXIT_CODE_BAD_SYNTAX; |
47 resultCode = CLI::EXIT_CODE_BAD_SYNTAX; |
52 } |
48 } |