| 68 | int mainEntryClickHouseFormat(int argc, char ** argv); |
| 69 | |
| 70 | int mainEntryClickHouseFormat(int argc, char ** argv) |
| 71 | { |
| 72 | using namespace DB; |
| 73 | |
| 74 | try |
| 75 | { |
| 76 | boost::program_options::options_description desc = createOptionsDescription("Allowed options", getTerminalWidth()); |
| 77 | desc.add_options() |
| 78 | ("query", po::value<std::string>(), "query to format") |
| 79 | ("help,h", "produce help message") |
| 80 | ("comments", "keep comments in the output") |
| 81 | ("hilite,highlight", "add syntax highlight with ANSI terminal escape sequences (can also use --highlight)") |
| 82 | ("oneline", "format in single line") |
| 83 | ("max_line_length", po::value<size_t>()->default_value(0), "format in single line queries with length less than specified") |
| 84 | ("quiet,q", "just check syntax, no output on success") |
| 85 | ("multiquery,n", "allow multiple queries in the same file") |
| 86 | ("obfuscate", "obfuscate instead of formatting") |
| 87 | ("backslash", "add a backslash at the end of each line of the formatted query") |
| 88 | ("no_rainbow_parentheses", "bypass highlighting of matching parentheses in distinct colors") |
| 89 | ("allow_settings_after_format_in_insert", "allow SETTINGS after FORMAT, but note, that this is not always safe") |
| 90 | ("seed", po::value<std::string>(), "seed (arbitrary string) that determines the result of obfuscation") |
| 91 | ("show_secrets", po::bool_switch()->default_value(false), "show secret values like passwords, API keys, etc.") |
| 92 | ("semicolons_inline", "In multiquery mode put semicolon on last line of query instead of a new line") |
| 93 | ; |
| 94 | |
| 95 | Settings cmd_settings; |
| 96 | cmd_settings.addToProgramOptions("max_parser_depth", desc); |
| 97 | cmd_settings.addToProgramOptions("max_query_size", desc); |
| 98 | |
| 99 | boost::program_options::variables_map options; |
| 100 | boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), options); |
| 101 | po::notify(options); |
| 102 | |
| 103 | if (options.contains("help")) |
| 104 | { |
| 105 | std::cout << "Usage: clickhouse format [options] < query" << std::endl; |
| 106 | std::cout << desc << std::endl; |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | bool hilite = options.contains("hilite"); |
| 111 | bool oneline = options.contains("oneline"); |
| 112 | bool quiet = options.contains("quiet"); |
| 113 | bool multiple = options.contains("multiquery"); |
| 114 | size_t max_line_length = options["max_line_length"].as<size_t>(); |
| 115 | bool obfuscate = options.contains("obfuscate"); |
| 116 | bool backslash = options.contains("backslash"); |
| 117 | bool rainbow_parentheses = !options.contains("no_rainbow_parentheses"); |
| 118 | bool allow_settings_after_format_in_insert = options.contains("allow_settings_after_format_in_insert"); |
| 119 | bool show_secrets = options["show_secrets"].as<bool>(); |
| 120 | bool semicolon_inline = options.contains("semicolons_inline"); |
| 121 | |
| 122 | std::function<void(std::string_view)> comments_callback; |
| 123 | if (options.contains("comments")) |
| 124 | comments_callback = [](const std::string_view comment) { std::cout << comment << '\n'; }; |
| 125 | |
| 126 | SharedContextHolder shared_context = Context::createShared(); |
| 127 | auto context = Context::createGlobal(shared_context.get()); |
nothing calls this directly
no test coverage detected