| 130 | |
| 131 | |
| 132 | int ClientEmbedded::run(const NameToNameMap & envVars, const String & first_query) |
| 133 | try |
| 134 | { |
| 135 | DB::setThreadName(ThreadName::LOCAL_SERVER_PTY); |
| 136 | |
| 137 | output_stream << std::fixed << std::setprecision(3); |
| 138 | error_stream << std::fixed << std::setprecision(3); |
| 139 | |
| 140 | /** |
| 141 | * To pass the environment variables through the SSH protocol you need to follow |
| 142 | * the format: ssh -o SetEnv="key1=value1 key2=value2" |
| 143 | * But the whole code is used to work with command line options, so we reconstruct them back. |
| 144 | */ |
| 145 | Arguments arguments; |
| 146 | arguments.reserve(envVars.size() * 2); |
| 147 | for (const auto & [key, value] : envVars) |
| 148 | { |
| 149 | arguments.emplace_back("--" + key); |
| 150 | arguments.emplace_back(value); |
| 151 | } |
| 152 | |
| 153 | OptionsDescription options_description; |
| 154 | addCommonOptions(options_description); |
| 155 | addSettingsToProgramOptionsAndSubscribeToChanges(options_description); |
| 156 | |
| 157 | po::variables_map options; |
| 158 | auto parser = po::command_line_parser(arguments) |
| 159 | .options(options_description.main_description.value()) |
| 160 | .allow_unregistered(); |
| 161 | auto parsed = parser.run(); |
| 162 | po::store(parsed, options); |
| 163 | po::notify(options); |
| 164 | |
| 165 | if (options.contains("version") || options.contains("V")) |
| 166 | { |
| 167 | showClientVersion(); |
| 168 | cleanup(); |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | if (options.contains("help")) |
| 173 | { |
| 174 | printHelpMessage(options_description); |
| 175 | cleanup(); |
| 176 | return 0; |
| 177 | } |
| 178 | |
| 179 | addOptionsToTheClientConfiguration(options); |
| 180 | |
| 181 | /// Apply settings specified as command line arguments (read environment variables). |
| 182 | global_context = session->sessionContext(); |
| 183 | global_context->setSettings(*cmd_settings); |
| 184 | |
| 185 | is_interactive = stdin_is_a_tty; |
| 186 | /// If a query is passed via SSH - just append it to the list of queries to execute: |
| 187 | /// ssh -i ~/.ssh/id_rsa default@localhost -p 9022 "SELECT 1" |
| 188 | if (!first_query.empty()) |
| 189 | queries.push_back(first_query); |
nothing calls this directly
no test coverage detected