mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 15:42:02 +00:00
Merge pull request #32841 from lingtaolf/feature/add-clickhouse-client-hints
Add clickhouse client hints
This commit is contained in:
commit
2ac7897470
@ -1731,7 +1731,13 @@ void ClientBase::parseAndCheckOptions(OptionsDescription & options_description,
|
||||
/// Check unrecognized options without positional options.
|
||||
auto unrecognized_options = po::collect_unrecognized(parsed.options, po::collect_unrecognized_mode::exclude_positional);
|
||||
if (!unrecognized_options.empty())
|
||||
{
|
||||
auto hints = this->getHints(unrecognized_options[0]);
|
||||
if (!hints.empty())
|
||||
throw Exception(ErrorCodes::UNRECOGNIZED_ARGUMENTS, "Unrecognized option '{}'. Maybe you meant {}", unrecognized_options[0], toString(hints));
|
||||
|
||||
throw Exception(ErrorCodes::UNRECOGNIZED_ARGUMENTS, "Unrecognized option '{}'", unrecognized_options[0]);
|
||||
}
|
||||
|
||||
/// Check positional options (options after ' -- ', ex: clickhouse-client -- <options>).
|
||||
unrecognized_options = po::collect_unrecognized(parsed.options, po::collect_unrecognized_mode::include_positional);
|
||||
@ -1809,6 +1815,25 @@ void ClientBase::init(int argc, char ** argv)
|
||||
;
|
||||
|
||||
addOptions(options_description);
|
||||
|
||||
auto getter = [](const auto & op)
|
||||
{
|
||||
String op_long_name = op->long_name();
|
||||
return "--" + String(op_long_name);
|
||||
};
|
||||
|
||||
if (options_description.main_description)
|
||||
{
|
||||
const auto & main_options = options_description.main_description->options();
|
||||
std::transform(main_options.begin(), main_options.end(), std::back_inserter(cmd_options), getter);
|
||||
}
|
||||
|
||||
if (options_description.external_description)
|
||||
{
|
||||
const auto & external_options = options_description.external_description->options();
|
||||
std::transform(external_options.begin(), external_options.end(), std::back_inserter(cmd_options), getter);
|
||||
}
|
||||
|
||||
parseAndCheckOptions(options_description, options, common_arguments);
|
||||
po::notify(options);
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "Common/NamePrompter.h"
|
||||
#include <Common/ProgressIndication.h>
|
||||
#include <Common/InterruptListener.h>
|
||||
#include <Common/ShellCommand.h>
|
||||
@ -37,7 +38,7 @@ void interruptSignalHandler(int signum);
|
||||
|
||||
class InternalTextLogs;
|
||||
|
||||
class ClientBase : public Poco::Util::Application
|
||||
class ClientBase : public Poco::Util::Application, public IHints<2, ClientBase>
|
||||
{
|
||||
|
||||
public:
|
||||
@ -48,6 +49,8 @@ public:
|
||||
|
||||
void init(int argc, char ** argv);
|
||||
|
||||
std::vector<String> getAllRegisteredNames() const override { return cmd_options; }
|
||||
|
||||
protected:
|
||||
void runInteractive();
|
||||
void runNonInteractive();
|
||||
@ -145,6 +148,7 @@ protected:
|
||||
|
||||
std::vector<String> queries_files; /// If not empty, queries will be read from these files
|
||||
std::vector<String> interleave_queries_files; /// If not empty, run queries from these files before processing every file from 'queries_files'.
|
||||
std::vector<String> cmd_options;
|
||||
|
||||
bool stdin_is_a_tty = false; /// stdin is a terminal.
|
||||
bool stdout_is_a_tty = false; /// stdout is a terminal.
|
||||
|
@ -0,0 +1 @@
|
||||
OK
|
8
tests/queries/0_stateless/02151_clickhouse_client_hints.sh
Executable file
8
tests/queries/0_stateless/02151_clickhouse_client_hints.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
# shellcheck source=../shell_config.sh
|
||||
. "$CURDIR"/../shell_config.sh
|
||||
|
||||
|
||||
$CLICKHOUSE_CLIENT --hardware_utilization 2>&1 | grep -q "Code: 552. DB::Exception: Unrecognized option '--hardware_utilization'. Maybe you meant \['--hardware-utilization'\]. (UNRECOGNIZED_ARGUMENTS)" && echo 'OK' || echo 'FAIL' ||:
|
Loading…
Reference in New Issue
Block a user