# HG changeset patch # User František Kučera # Date 1620577149 -7200 # Node ID bc6e11cccdf48e33dd15bdde348eb03d112d59bd # Parent cc6ffeba0fe506bed330d1f965170a1335cc5cbf add boolean parameter to --list-data-sources + allow listing and SELECTing at the same time diff -r cc6ffeba0fe5 -r bc6e11cccdf4 bash-completion.sh --- a/bash-completion.sh Mon Oct 26 00:00:35 2020 +0100 +++ b/bash-completion.sh Sun May 09 18:19:09 2021 +0200 @@ -33,6 +33,11 @@ "boolean" ) + BOOLEAN_VALUES=( + "true" + "false" + ) + DATA_SOURCE_STRING=( "Driver=SQLite3;Database=file::memory:" "Driver=SQLite3;Database=file:temp-relpipe.sqlite" @@ -43,6 +48,7 @@ elif [[ "$w2" == "--relation" && "x$w0" == "x" ]]; then COMPREPLY=('"SELECT * FROM "') elif [[ "$w1" == "--type-cast" && "x$w0" == "x" ]]; then COMPREPLY=("''") elif [[ "$w2" == "--type-cast" ]]; then COMPREPLY=($(compgen -W "${DATA_TYPE[*]}" -- "$w0")) + elif [[ "$w1" == "--list-data-sources" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) elif [[ "$w1" == "--parameter" && "x$w0" == "x" ]]; then COMPREPLY=("''") elif [[ "$w1" == "--copy" && "x$w0" == "x" ]]; then COMPREPLY=("'.+'") elif [[ "$w1" == "--copy-renamed" && "x$w0" == "x" ]]; then COMPREPLY=("'.+'") diff -r cc6ffeba0fe5 -r bc6e11cccdf4 src/CLIParser.h --- a/src/CLIParser.h Mon Oct 26 00:00:35 2020 +0100 +++ b/src/CLIParser.h Sun May 09 18:19:09 2021 +0200 @@ -38,6 +38,15 @@ else throw relpipe::cli::RelpipeCLIException(L"Missing CLI argument" + (i > 0 ? (L" after " + arguments[i - 1]) : L""), relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); } + /** + * TODO: use a common method + */ + bool parseBoolean(const string_t& value) { + if (value == L"true") return true; + else if (value == L"false") return false; + else throw relpipe::cli::RelpipeCLIException(L"Unable to parse boolean value: " + value + L" (expecting true or false)", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); + } + void addQuery(Configuration& c, Statement& currentQuery) { if (currentQuery.sql.size()) { c.statements.push_back(currentQuery); @@ -85,7 +94,7 @@ } else if (option == OPTION_DATA_SOURCE_STRING) { c.dataSourceString = readNext(arguments, i); } else if (option == OPTION_LIST_DATA_SOURCES) { - c.listDataSources = true; + c.listDataSources = parseBoolean(readNext(arguments, i)); } else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); } addQuery(c, currentQuery); // last relation diff -r cc6ffeba0fe5 -r bc6e11cccdf4 src/relpipe-tr-sql.cpp --- a/src/relpipe-tr-sql.cpp Mon Oct 26 00:00:35 2020 +0100 +++ b/src/relpipe-tr-sql.cpp Sun May 09 18:19:09 2021 +0200 @@ -59,7 +59,10 @@ if (configuration.listDataSources) { // --list-data-sources: SqlHandler::listDataSources(writer.get(), driverManager.get()); - } else if (std::regex_match(cli.programName(), std::wregex(L"^(.*/)?relpipe-in-sql$"))) { + if (isatty(fileno(stdin)) && configuration.statements.empty() && configuration.copyRelations.empty()) goto end; + } + + if (std::regex_match(cli.programName(), std::wregex(L"^(.*/)?relpipe-in-sql$"))) { // relpipe-in-sql: if (cli.arguments().size() == 0) configuration.copyRelations.push_back({L".*", L"", false}); configuration.sqlBeforeRelational = isatty(fileno(stdin)) ? nullptr : &std::wcin; @@ -74,6 +77,7 @@ reader->process(); } +end: resultCode = CLI::EXIT_CODE_SUCCESS; } catch (RelpipeCLIException& e) {