--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/RelpipeCLIException.h Sat Jul 28 15:11:07 2018 +0200
@@ -0,0 +1,36 @@
+#pragma once
+
+#include <string>
+
+#include "CLI.h"
+
+using namespace std;
+
+namespace relpipe {
+namespace cli {
+
+/**
+ * TODO: move to relpipe-lib-cli (a common header-only library)
+ */
+class RelpipeCLIException {
+private:
+ wstring message;
+ int exitCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
+public:
+
+ RelpipeCLIException(wstring message, int exitCode) :
+ message(message), exitCode(exitCode) {
+ }
+
+ wstring getMessge() {
+ return message;
+ }
+
+ int getExitCode() {
+ return exitCode;
+ }
+
+};
+
+}
+}
\ No newline at end of file
--- a/nbproject/configurations.xml Sat Jul 28 14:26:58 2018 +0200
+++ b/nbproject/configurations.xml Sat Jul 28 15:11:07 2018 +0200
@@ -8,6 +8,7 @@
<itemPath>CLI.h</itemPath>
<itemPath>Command.h</itemPath>
<itemPath>DemoCommand.h</itemPath>
+ <itemPath>RelpipeCLIException.h</itemPath>
</logicalFolder>
<logicalFolder name="ResourceFiles"
displayName="Resource Files"
@@ -62,6 +63,8 @@
</item>
<item path="DemoCommand.h" ex="false" tool="3" flavor2="0">
</item>
+ <item path="RelpipeCLIException.h" ex="false" tool="3" flavor2="0">
+ </item>
<item path="relpipe-in-cli.cpp" ex="false" tool="1" flavor2="0">
</item>
</conf>
@@ -99,6 +102,8 @@
</item>
<item path="DemoCommand.h" ex="false" tool="3" flavor2="0">
</item>
+ <item path="RelpipeCLIException.h" ex="false" tool="3" flavor2="0">
+ </item>
<item path="relpipe-in-cli.cpp" ex="false" tool="1" flavor2="0">
</item>
</conf>
--- 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;
}