relpipe-in-cli.cpp
branchv_0
changeset 14 cfed80d11caa
parent 13 5e95f0c0a4f9
child 15 dc2121dec856
--- a/relpipe-in-cli.cpp	Sat Jul 28 14:26:58 2018 +0200
+++ b/relpipe-in-cli.cpp	Sat Jul 28 15:11:07 2018 +0200
@@ -9,6 +9,7 @@
 #include <TypeId.h>
 
 #include "CLI.h"
+#include "RelpipeCLIException.h"
 #include "Command.h"
 #include "ArgumentsCommand.h"
 #include "DemoCommand.h"
@@ -20,7 +21,7 @@
 Command* findCommand(string_t commandName) {
 	if (commandName == L"demo") return new DemoCommand();
 	else if (commandName == L"generate") return new ArgumentsCommand();
-	else throw new RelpipeWriterException(L"Unknown command: " + commandName); // TODO: CLI expcetion
+	else throw RelpipeCLIException(L"Unknown command: " + commandName, CLI::EXIT_CODE_UNKNOWN_COMMAND);
 }
 
 int main(int argc, char** argv) {
@@ -43,11 +44,14 @@
 			resultCode = CLI::EXIT_CODE_SUCCESS;
 
 		} else {
-			fwprintf(stderr, L"Missing command…\n");
-			resultCode = CLI::EXIT_CODE_BAD_SYNTAX;
+			throw RelpipeCLIException(L"Missing command…", CLI::EXIT_CODE_BAD_SYNTAX);
 		}
+	} catch (RelpipeCLIException e) {
+		fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessge().c_str());
+		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
+		resultCode = e.getExitCode();
 	} catch (RelpipeWriterException e) {
-		fwprintf(stderr, L"Caught exception: %ls\n", e.getMessge().c_str());
+		fwprintf(stderr, L"Caught Writer exception: %ls\n", e.getMessge().c_str());
 		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
 		resultCode = CLI::EXIT_CODE_DATA_ERROR;
 	}