rename --records-from-stdin to --records-on-stdin and add boolean parameter v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Thu, 24 Sep 2020 20:37:52 +0200
branchv_0
changeset 46 ab27422a34b0
parent 45 5e5815fdcd2d
child 47 329757999664
rename --records-from-stdin to --records-on-stdin and add boolean parameter
bash-completion.sh
src/CLIParser.h
--- a/bash-completion.sh	Thu Sep 24 16:03:05 2020 +0200
+++ b/bash-completion.sh	Thu Sep 24 20:37:52 2020 +0200
@@ -28,7 +28,7 @@
 		"boolean"
 	)
 
-	WRITE_HEADER=(
+	BOOLEAN_VALUES=(
 		"true"
 		"false"
 	)
@@ -36,7 +36,8 @@
 	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"))
+	elif [[ "$w1" == "--write-header"                                   ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
+	elif [[ "$w1" == "--records-on-stdin"                               ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
 	else
 		OPTIONS=(
 			"--relation"
@@ -44,7 +45,7 @@
 			"--attribute"
 			"--record"
 			"--records"
-			"--records-from-stdin"
+			"--records-on-stdin"
 		)
 		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
 	fi
--- a/src/CLIParser.h	Thu Sep 24 16:03:05 2020 +0200
+++ b/src/CLIParser.h	Thu Sep 24 20:37:52 2020 +0200
@@ -99,8 +99,10 @@
 			} else if (option == OPTION_RECORDS) {
 				while (i < arguments.size()) readNextRecord(arguments, i, currentRelation);
 			} else if (option == OPTION_RECORDS_STDIN) {
-				for (RelationConfiguration r : c.relationConfigurations) if (r.valueStream) throw relpipe::cli::RelpipeCLIException(L"Only one relation can read data from STDIN.", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
-				currentRelation.valueStream = &std::cin;
+				if (parseBoolean(readNext(arguments, i))) {
+					for (RelationConfiguration r : c.relationConfigurations) if (r.valueStream) throw relpipe::cli::RelpipeCLIException(L"Only one relation can read data from STDIN.", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
+					currentRelation.valueStream = &std::cin;
+				}
 			} else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
 		}
 		addRelation(c, currentRelation); // last relation
@@ -117,7 +119,7 @@
 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";
-const relpipe::writer::string_t CLIParser::OPTION_RECORDS_STDIN = L"--records-from-stdin";
+const relpipe::writer::string_t CLIParser::OPTION_RECORDS_STDIN = L"--records-on-stdin";
 
 }
 }