Add hints for clickhouse client options

This commit is contained in:
凌涛 2021-12-16 17:42:49 +08:00
parent 2d4b27a6b5
commit ad34217873
2 changed files with 22 additions and 1 deletions

View File

@ -1635,7 +1635,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);
@ -1713,6 +1719,17 @@ 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);
};
const auto & main_options = options_description.main_description->options();
const auto & external_options = options_description.external_description->options();
std::transform(main_options.begin(), main_options.end(), std::back_inserter(cmd_options), getter);
std::transform(external_options.begin(), external_options.end(), std::back_inserter(cmd_options), getter);
parseAndCheckOptions(options_description, options, common_arguments);
po::notify(options);

View File

@ -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.