blob: 289573190bfbe3e59aaac4e89aa3b78cf13f91c4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#include <yql/essentials/sql/v1/complete/sql_complete.h>
#include <library/cpp/getopt/last_getopt.h>
#include <util/stream/file.h>
int Run(int argc, char* argv[]) {
NLastGetopt::TOpts opts = NLastGetopt::TOpts::Default();
TString inFileName;
TMaybe<ui64> pos;
opts.AddLongOption('i', "input", "input file").RequiredArgument("input").StoreResult(&inFileName);
opts.AddLongOption('p', "pos", "position").StoreResult(&pos);
opts.SetFreeArgsNum(0);
opts.AddHelpOption();
NLastGetopt::TOptsParseResult res(&opts, argc, argv);
THolder<TUnbufferedFileInput> inFile;
if (!inFileName.empty()) {
inFile.Reset(new TUnbufferedFileInput(inFileName));
}
IInputStream& in = inFile ? *inFile.Get() : Cin;
auto queryString = in.ReadAll();
auto engine = NSQLComplete::MakeSqlCompletionEngine();
NSQLComplete::TCompletionInput input;
input.Text = queryString;
if (pos) {
input.CursorPosition = *pos;
} else {
input.CursorPosition = queryString.size();
}
auto output = engine->Complete(input);
for (const auto& c : output.Candidates) {
Cout << "[" << c.Kind << "] " << c.Content << "\n";
}
return 0;
}
int main(int argc, char* argv[]) {
try {
return Run(argc, argv);
} catch (const yexception& e) {
Cerr << "Caught exception:" << e.what() << Endl;
return 1;
} catch (...) {
Cerr << CurrentExceptionMessage() << Endl;
return 1;
}
return 0;
}
|