add option: --write-header v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Tue, 22 Sep 2020 21:32:14 +0200
branchv_0
changeset 44 dd7094457e44
parent 43 3c8ea5dcf793
child 45 5e5815fdcd2d
add option: --write-header we can omit the relation's header and generate just the records and append them to an existing relational stream: (relpipe-in-cli --relation rrr --attribute a integer; relpipe-in-cli --write-header false --relation rrr --attribute XXX integer --records 1 2 3) | relpipe-out-tabular
bash-completion.sh
src/CLICommand.h
src/CLIParser.h
src/Configuration.h
--- a/bash-completion.sh	Tue Sep 22 21:00:30 2020 +0200
+++ b/bash-completion.sh	Tue Sep 22 21:32:14 2020 +0200
@@ -28,12 +28,19 @@
 		"boolean"
 	)
 
+	WRITE_HEADER=(
+		"true"
+		"false"
+	)
+
 	if   [[ "$w1" == "--relation"                      && "x$w0" == "x" ]];    then COMPREPLY=("''")
 	elif [[ "$w1" == "--attribute"                     && "x$w0" == "x" ]];    then COMPREPLY=("''")
 	elif [[ "$w2" == "--attribute"                                      ]];    then COMPREPLY=($(compgen -W "${DATA_TYPE[*]}" -- "$w0"))
+	elif [[ "$w1" == "--write-header"                                  ]];    then COMPREPLY=($(compgen -W "${WRITE_HEADER[*]}" -- "$w0"))
 	else
 		OPTIONS=(
 			"--relation"
+			"--write-header"
 			"--attribute"
 			"--record"
 			"--records"
--- a/src/CLICommand.h	Tue Sep 22 21:00:30 2020 +0200
+++ b/src/CLICommand.h	Tue Sep 22 21:32:14 2020 +0200
@@ -35,7 +35,7 @@
 		// Write header / metadata:
 		std::vector<relpipe::writer::AttributeMetadata> attributesMetadata;
 		for (AttributeRecipe ar : configuration.attributes) attributesMetadata.push_back({ar.name, ar.type});
-		writer->startRelation(configuration.relation, attributesMetadata, true);
+		writer->startRelation(configuration.relation, attributesMetadata, configuration.writeHeader);
 
 		// Write records from CLI:
 		for (auto value : configuration.values) writer->writeAttribute(value);
--- a/src/CLIParser.h	Tue Sep 22 21:00:30 2020 +0200
+++ b/src/CLIParser.h	Tue Sep 22 21:32:14 2020 +0200
@@ -71,6 +71,7 @@
 public:
 
 	static const relpipe::writer::string_t OPTION_RELATION;
+	static const relpipe::writer::string_t OPTION_WRITE_HEADER;
 	static const relpipe::writer::string_t OPTION_ATTRIBUTE;
 	static const relpipe::writer::string_t OPTION_RECORD;
 	static const relpipe::writer::string_t OPTION_RECORDS;
@@ -86,6 +87,8 @@
 			if (option == OPTION_RELATION) {
 				addRelation(c, currentRelation); // previous relation
 				currentRelation.relation = readNext(arguments, i);
+			} else if (option == OPTION_WRITE_HEADER) {
+				currentRelation.writeHeader = parseBoolean(readNext(arguments, i));
 			} else if (option == OPTION_ATTRIBUTE) {
 				AttributeRecipe attribute;
 				attribute.name = readNext(arguments, i);
@@ -110,6 +113,7 @@
 };
 
 const relpipe::writer::string_t CLIParser::OPTION_RELATION = L"--relation";
+const relpipe::writer::string_t CLIParser::OPTION_WRITE_HEADER = L"--write-header";
 const relpipe::writer::string_t CLIParser::OPTION_ATTRIBUTE = L"--attribute";
 const relpipe::writer::string_t CLIParser::OPTION_RECORD = L"--record";
 const relpipe::writer::string_t CLIParser::OPTION_RECORDS = L"--records";
--- a/src/Configuration.h	Tue Sep 22 21:00:30 2020 +0200
+++ b/src/Configuration.h	Tue Sep 22 21:32:14 2020 +0200
@@ -44,6 +44,7 @@
 	}
 
 	relpipe::writer::string_t relation;
+	relpipe::writer::boolean_t writeHeader = true;
 	std::vector<AttributeRecipe> attributes;
 	std::vector<relpipe::writer::string_t> values;
 	std::istream* valueStream = nullptr;