MCPcopy Create free account
hub / github.com/ByConity/ByConity / mainEntryClickHouseFormat

Function mainEntryClickHouseFormat

programs/format/Format.cpp:41–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39}
40
41int mainEntryClickHouseFormat(int argc, char ** argv)
42{
43 using namespace DB;
44
45 boost::program_options::options_description desc = createOptionsDescription("Allowed options", getTerminalWidth());
46 desc.add_options()
47 ("help,h", "produce help message")
48 ("hilite", "add syntax highlight with ANSI terminal escape sequences")
49 ("oneline", "format in single line")
50 ("quiet,q", "just check syntax, no output on success")
51 ("multiquery,n", "allow multiple queries in the same file")
52 ("obfuscate", "obfuscate instead of formatting")
53 ("backslash", "add a backslash at the end of each line of the formatted query")
54 ("seed", po::value<std::string>(), "seed (arbitrary string) that determines the result of obfuscation")
55 ;
56
57 boost::program_options::variables_map options;
58 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), options);
59
60 if (options.count("help"))
61 {
62 std::cout << "Usage: " << argv[0] << " [options] < query" << std::endl;
63 std::cout << desc << std::endl;
64 return 1;
65 }
66
67 try
68 {
69 bool hilite = options.count("hilite");
70 bool oneline = options.count("oneline");
71 bool quiet = options.count("quiet");
72 bool multiple = options.count("multiquery");
73 bool obfuscate = options.count("obfuscate");
74 bool backslash = options.count("backslash");
75
76 if (quiet && (hilite || oneline || obfuscate))
77 {
78 std::cerr << "Options 'hilite' or 'oneline' or 'obfuscate' have no sense in 'quiet' mode." << std::endl;
79 return 2;
80 }
81
82 if (obfuscate && (hilite || oneline || quiet))
83 {
84 std::cerr << "Options 'hilite' or 'oneline' or 'quiet' have no sense in 'obfuscate' mode." << std::endl;
85 return 2;
86 }
87
88 String query;
89 ReadBufferFromFileDescriptor in(STDIN_FILENO);
90 readStringUntilEOF(query, in);
91
92 if (obfuscate)
93 {
94 WordMap obfuscated_words_map;
95 WordSet used_nouns;
96 SipHash hash_func;
97
98 if (options.count("seed"))

Callers 1

mainFunction · 0.85

Calls 15

createOptionsDescriptionFunction · 0.85
getTerminalWidthFunction · 0.85
storeFunction · 0.85
readStringUntilEOFFunction · 0.85
registerFunctionsFunction · 0.85
registerTableFunctionsFunction · 0.85
registerStoragesFunction · 0.85
obfuscateQueriesFunction · 0.85
formatASTFunction · 0.85

Tested by

no test coverage detected