optional custom relation name v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Wed, 09 Jan 2019 23:18:16 +0100
branchv_0
changeset 2 e83895da3e8f
parent 1 5eb4d149c6e2
child 3 d7907be4cc40
optional custom relation name
src/relpipe-in-csv.cpp
--- a/src/relpipe-in-csv.cpp	Wed Jan 09 23:04:51 2019 +0100
+++ b/src/relpipe-in-csv.cpp	Wed Jan 09 23:18:16 2019 +0100
@@ -82,7 +82,7 @@
 	return false;
 }
 
-void processDataStream(ostream &output, istream& input) {
+void processDataStream(ostream &output, istream& input, const vector<string_t>& args) {
 	wstring_convert < codecvt_utf8<wchar_t>> convertor; // UTF-8 is required for CSV
 	std::shared_ptr<RelationalWriter> writer(Factory::create(output));
 	vector<AttributeMetadata> metadata;
@@ -101,7 +101,7 @@
 			metadata.push_back(am);
 			if (lastInRecord) {
 				headerDone = true;
-				writer->startRelation(L"csv", metadata, true); // TODO: support also custom relation name passed as CLI parameter
+				writer->startRelation(args.size() > 0 ? args[0] : L"csv", metadata, true);
 			}
 		}
 
@@ -118,7 +118,7 @@
 	int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
 
 	try {
-		processDataStream(cout, cin);
+		processDataStream(cout, cin, cli.arguments());
 		resultCode = CLI::EXIT_CODE_SUCCESS;
 	} catch (RelpipeWriterException e) {
 		fwprintf(stderr, L"Caught Writer exception: %ls\n", e.getMessge().c_str());