18 using namespace relpipe::writer; |
19 using namespace relpipe::writer; |
19 |
20 |
20 Command* findCommand(string_t commandName) { |
21 Command* findCommand(string_t commandName) { |
21 if (commandName == L"demo") return new DemoCommand(); |
22 if (commandName == L"demo") return new DemoCommand(); |
22 else if (commandName == L"generate") return new ArgumentsCommand(); |
23 else if (commandName == L"generate") return new ArgumentsCommand(); |
23 else throw new RelpipeWriterException(L"Unknown command: " + commandName); // TODO: CLI expcetion |
24 else throw RelpipeCLIException(L"Unknown command: " + commandName, CLI::EXIT_CODE_UNKNOWN_COMMAND); |
24 } |
25 } |
25 |
26 |
26 int main(int argc, char** argv) { |
27 int main(int argc, char** argv) { |
27 setlocale(LC_ALL, ""); |
28 setlocale(LC_ALL, ""); |
28 CLI cli(argc, argv); |
29 CLI cli(argc, argv); |
41 std::shared_ptr<Command> command(findCommand(commandName)); |
42 std::shared_ptr<Command> command(findCommand(commandName)); |
42 command->process(cin, cout, commandName, arguments); |
43 command->process(cin, cout, commandName, arguments); |
43 resultCode = CLI::EXIT_CODE_SUCCESS; |
44 resultCode = CLI::EXIT_CODE_SUCCESS; |
44 |
45 |
45 } else { |
46 } else { |
46 fwprintf(stderr, L"Missing command…\n"); |
47 throw RelpipeCLIException(L"Missing command…", CLI::EXIT_CODE_BAD_SYNTAX); |
47 resultCode = CLI::EXIT_CODE_BAD_SYNTAX; |
|
48 } |
48 } |
|
49 } catch (RelpipeCLIException e) { |
|
50 fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessge().c_str()); |
|
51 fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
|
52 resultCode = e.getExitCode(); |
49 } catch (RelpipeWriterException e) { |
53 } catch (RelpipeWriterException e) { |
50 fwprintf(stderr, L"Caught exception: %ls\n", e.getMessge().c_str()); |
54 fwprintf(stderr, L"Caught Writer exception: %ls\n", e.getMessge().c_str()); |
51 fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
55 fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
52 resultCode = CLI::EXIT_CODE_DATA_ERROR; |
56 resultCode = CLI::EXIT_CODE_DATA_ERROR; |
53 } |
57 } |
54 |
58 |
55 return resultCode; |
59 return resultCode; |