#include <cstdlib>
#include <memory>
#include <tuple>
#include <RelationalWriter.h>
#include <RelpipeWriterException.h>
#include <Factory.h>
#include <TypeId.h>
#include "CLI.h"
#include "Command.h"
#include "ArgumentsCommand.h"
#include "DemoCommand.h"
int main(int argc, char** argv) {
using namespace relpipe::cli;
using namespace relpipe::in::cli;
using namespace relpipe::writer;
setlocale(LC_ALL, "");
CLI cli(argc, argv);
int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
try {
if (cli.arguments().size() > 0) {
const wstring action = cli.arguments()[0];
vector<wstring> arguments(cli.arguments().size() - 1);
for (int i = 1; i < cli.arguments().size(); i++) {
arguments[i - 1] = cli.arguments()[i];
}
if (action == L"demo") {
DemoCommand command;
command.process(cin, cout, action, arguments);
resultCode = CLI::EXIT_CODE_SUCCESS;
} else if (action == L"generate") {
ArgumentsCommand command;
command.process(cin, cout, action, arguments);
resultCode = CLI::EXIT_CODE_SUCCESS;
} else {
fwprintf(stderr, L"Unknown command: %ls\n", action.c_str());
resultCode = CLI::EXIT_CODE_UNKNOWN_COMMAND;
}
} else {
fwprintf(stderr, L"Missing command…\n");
resultCode = CLI::EXIT_CODE_BAD_SYNTAX;
}
} catch (RelpipeWriterException e) {
fwprintf(stderr, L"Caught 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;
}
return resultCode;
}