Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions programs/client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,9 @@ void Client::addAndCheckOptions(OptionsDescription & options_description, po::va
/// Main commandline options related to client functionality and all parameters from Settings.
options_description.main_description->add_options()
("config,c", po::value<std::string>(), "config-file path (another shorthand)")
("host,h", po::value<std::string>()->default_value("localhost"), "server host")
("host,h", po::value<std::vector<HostPort>>()->multitoken()->default_value({{"localhost"}}, "localhost"),
"list of server hosts with optionally assigned port to connect. Every argument looks like '<host>[:<port>] for example"
"'localhost:port'. If port isn't assigned, connection is made by port from '--port' param")
("port", po::value<int>()->default_value(9000), "server port")
("secure,s", "Use TLS connection")
("user,u", po::value<std::string>()->default_value("default"), "user")
Expand Down Expand Up @@ -1120,7 +1122,12 @@ void Client::processOptions(const OptionsDescription & options_description,
if (options.count("config"))
config().setString("config-file", options["config"].as<std::string>());
if (options.count("host") && !options["host"].defaulted())
config().setString("host", options["host"].as<std::string>());
{
hosts_ports = options["host"].as<std::vector<HostPort>>();
config().setString("host", hosts_ports[0].host);
if (hosts_ports[0].port.has_value())
config().setInt("port", hosts_ports[0].port.value());
}
if (options.count("interleave-queries-file"))
interleave_queries_files = options["interleave-queries-file"].as<std::vector<std::string>>();
if (options.count("pager"))
Expand Down
2 changes: 1 addition & 1 deletion src/Client/ClientBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,7 @@ void ClientBase::init(int argc, char ** argv)

/// Output of help message.
if (options.count("help")
|| (options.count("host") && options["host"].as<std::string>() == "elp")) /// If user writes -help instead of --help.
|| (options.count("host") && options["host"].as<std::vector<HostPort>>()[0].host == "elp")) /// If user writes -help instead of --help.
{
printHelpMessage(options_description);
exit(0);
Expand Down
18 changes: 18 additions & 0 deletions src/Client/ClientBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,24 @@ class ClientBase : public Poco::Util::Application
int query_fuzzer_runs = 0;

QueryProcessingStage::Enum query_processing_stage;

struct HostPort
{
String host;
std::optional<int> port{};
friend std::istream & operator>>(std::istream & in, HostPort & hostPort) {
String
host_with_port,
delimiter = ":";
in >> host_with_port;
size_t delimiter_pos = host_with_port.find(delimiter);
hostPort.host = host_with_port.substr(0, delimiter_pos);
if (delimiter_pos < host_with_port.length())
hostPort.port = std::stoi(host_with_port.substr(delimiter_pos + 1, host_with_port.length()));
return in;
}
};
std::vector<HostPort> hosts_ports{};
};

}