clickhouse-client: fix --help without tty

stdin_is_not_tty is detected too late when the --help message is
printed, so fix this and do not call ioctl if stdin is not tty.

Before this patch:
  $ clickhouse-client --help < /dev/null

debug build:
  $ dbms/programs/clickhouse-client --help < /dev/null
  Main options:
    --help
  clickhouse-client: ../contrib/boost/libs/program_options/src/options_description.cpp:542:
  void boost::program_options::{anonymous}::format_description(std::ostream&, const string&, unsigned int, unsigned int): Assertion `line_length > first_column_width' failed.
  Aborted (core dumped)

release build:
  $ dbms/programs/clickhouse-client --help < /dev/null
  .... print lots of empty lines and so forth ...

v2: add a test and bsdutils into image for tests
v3: adjust minimal cols to the length of one of the longest arguments,
since with line_length=3 boost will bail anyway (under script(1)
ioctl(TIOCGWINSZ) returnes ws_col=0)
上级 faeca57d
......@@ -101,6 +101,7 @@ namespace ErrorCodes
extern const int LOGICAL_ERROR;
extern const int CANNOT_SET_SIGNAL_HANDLER;
extern const int CANNOT_READLINE;
extern const int SYSTEM_ERROR;
}
......@@ -295,7 +296,6 @@ private:
/// The value of the option is used as the text of query (or of multiple queries).
/// If stdin is not a terminal, INSERT data for the first query is read from it.
/// - stdin is not a terminal. In this case queries are read from it.
stdin_is_not_tty = !isatty(STDIN_FILENO);
if (stdin_is_not_tty || config().has("query"))
is_interactive = false;
......@@ -610,9 +610,6 @@ private:
try
{
/// Determine the terminal size.
ioctl(0, TIOCGWINSZ, &terminal_size);
if (!process(input))
break;
}
......@@ -1568,7 +1565,7 @@ public:
}
}
ioctl(0, TIOCGWINSZ, &terminal_size);
stdin_is_not_tty = !isatty(STDIN_FILENO);
namespace po = boost::program_options;
......@@ -1576,7 +1573,11 @@ public:
unsigned min_description_length = line_length / 2;
if (!stdin_is_not_tty)
{
line_length = std::max(3U, static_cast<unsigned>(terminal_size.ws_col));
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &terminal_size))
throwFromErrno("Cannot obtain terminal window size (ioctl TIOCGWINSZ)", ErrorCodes::SYSTEM_ERROR);
line_length = std::max(
static_cast<unsigned>(strlen("--http_native_compression_disable_checksumming_on_decompress ")),
static_cast<unsigned>(terminal_size.ws_col));
min_description_length = std::min(min_description_length, line_length - 2);
}
......
......@@ -19,6 +19,7 @@ RUN apt-get update && env DEBIAN_FRONTEND=noninteractive apt-get install --yes -
tzdata \
libreadline-dev \
libicu-dev \
bsdutils \
curl
ENV TZ=Europe/Moscow
......
#!/usr/bin/env bash
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. $CURDIR/../shell_config.sh
set -e
set -o pipefail
${CLICKHOUSE_CLIENT} --help </dev/null | wc -L
script -e -q -c "${CLICKHOUSE_CLIENT} --help" /dev/null </dev/null >/dev/null
......@@ -61,7 +61,7 @@ Description: debugging symbols for clickhouse-common-static
Package: clickhouse-test
Priority: optional
Architecture: all
Depends: ${shlibs:Depends}, ${misc:Depends}, clickhouse-client, bash, expect, python, python-lxml, python-termcolor, python-requests, curl, perl, sudo, openssl, netcat-openbsd, telnet, brotli
Depends: ${shlibs:Depends}, ${misc:Depends}, clickhouse-client, bash, expect, python, python-lxml, python-termcolor, python-requests, curl, perl, sudo, openssl, netcat-openbsd, telnet, brotli, bsdutils
Description: ClickHouse tests
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册