clickhouse-format support option --query

This commit is contained in:
凌涛 2021-09-24 18:16:46 +08:00
parent 56c0767063
commit 08983e432b
3 changed files with 19 additions and 2 deletions

View File

@ -44,6 +44,7 @@ int mainEntryClickHouseFormat(int argc, char ** argv)
boost::program_options::options_description desc = createOptionsDescription("Allowed options", getTerminalWidth());
desc.add_options()
("query", po::value<std::string>(), "query to format")
("help,h", "produce help message")
("hilite", "add syntax highlight with ANSI terminal escape sequences")
("oneline", "format in single line")
@ -86,8 +87,16 @@ int mainEntryClickHouseFormat(int argc, char ** argv)
}
String query;
ReadBufferFromFileDescriptor in(STDIN_FILENO);
readStringUntilEOF(query, in);
if (options.count("query"))
{
query = options["query"].as<std::string>();
}
else
{
ReadBufferFromFileDescriptor in(STDIN_FILENO);
readStringUntilEOF(query, in);
}
if (obfuscate)
{

View File

@ -0,0 +1 @@
SELECT 1

View File

@ -0,0 +1,7 @@
#!/usr/bin/env bash
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh
${CLICKHOUSE_FORMAT} --query "SELECT 1"