Skip to content

Commit ce040d6

Browse files
vityamanblinkov
authored andcommitted
#9056 Format module commands/interactive (#15212)
Signed-off-by: vityaman <[email protected]>
1 parent e9eee10 commit ce040d6

File tree

8 files changed

+50
-58
lines changed

8 files changed

+50
-58
lines changed

ydb/public/lib/ydb_cli/commands/interactive/interactive_cli.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
#include <ydb/public/lib/ydb_cli/commands/ydb_service_table.h>
1212
#include <ydb/public/lib/ydb_cli/commands/ydb_sql.h>
1313

14-
namespace NYdb {
15-
namespace NConsoleClient {
16-
14+
namespace NYdb::NConsoleClient {
1715

1816
namespace {
1917

@@ -43,13 +41,14 @@ class Lexer {
4341

4442
private:
4543
std::string_view Input;
46-
const char * Position = nullptr;
44+
const char* Position = nullptr;
4745
};
4846

4947
Lexer::Lexer(std::string_view input)
5048
: Input(input)
5149
, Position(Input.data())
52-
{}
50+
{
51+
}
5352

5453
std::optional<Token> Lexer::GetNextToken() {
5554
while (Position < Input.end() && std::isspace(*Position)) {
@@ -60,7 +59,7 @@ std::optional<Token> Lexer::GetNextToken() {
6059
return {};
6160
}
6261

63-
const char * tokenStart = Position;
62+
const char* tokenStart = Position;
6463
if (IsSeparatedTokenSymbol(*Position)) {
6564
++Position;
6665
} else {
@@ -92,7 +91,7 @@ struct InteractiveCLIState {
9291
NTable::ECollectQueryStatsMode CollectStatsMode = NTable::ECollectQueryStatsMode::None;
9392
};
9493

95-
std::optional<NTable::ECollectQueryStatsMode> TryParseCollectStatsMode(const std::vector<Token> & tokens) {
94+
std::optional<NTable::ECollectQueryStatsMode> TryParseCollectStatsMode(const std::vector<Token>& tokens) {
9695
size_t tokensSize = tokens.size();
9796

9897
if (tokensSize > 4) {
@@ -107,7 +106,7 @@ std::optional<NTable::ECollectQueryStatsMode> TryParseCollectStatsMode(const std
107106
return statsMode;
108107
}
109108

110-
void ParseSetCommand(const std::vector<Token> & tokens, InteractiveCLIState & interactiveCLIState) {
109+
void ParseSetCommand(const std::vector<Token>& tokens, InteractiveCLIState& interactiveCLIState) {
111110
if (tokens.size() == 1) {
112111
Cerr << "Missing variable name for \"SET\" special command." << Endl;
113112
} else if (tokens.size() == 2 || tokens[2].data != "=") {
@@ -123,12 +122,13 @@ void ParseSetCommand(const std::vector<Token> & tokens, InteractiveCLIState & in
123122
}
124123
}
125124

126-
}
125+
} // namespace
127126

128-
TInteractiveCLI::TInteractiveCLI(TClientCommand::TConfig & config, std::string prompt)
127+
TInteractiveCLI::TInteractiveCLI(TClientCommand::TConfig& config, std::string prompt)
129128
: Config(config)
130129
, Prompt(std::move(prompt))
131-
{}
130+
{
131+
}
132132

133133
void TInteractiveCLI::Run() {
134134
TFsPath homeDirPath(HomeDir);
@@ -139,7 +139,7 @@ void TInteractiveCLI::Run() {
139139

140140
while (auto lineOptional = lineReader->ReadLine())
141141
{
142-
auto & line = *lineOptional;
142+
auto& line = *lineOptional;
143143
if (line.empty()) {
144144
continue;
145145
}
@@ -184,17 +184,16 @@ void TInteractiveCLI::Run() {
184184
sqlCommand.SetCollectStatsMode(std::move(queryStatsMode));
185185
sqlCommand.SetSyntax("yql");
186186
sqlCommand.Run(Config);
187-
} catch (NStatusHelpers::TYdbErrorException &error) {
187+
} catch (NStatusHelpers::TYdbErrorException& error) {
188188
Cerr << error;
189-
} catch (yexception & error) {
189+
} catch (yexception& error) {
190190
Cerr << error;
191-
} catch (std::exception & error) {
191+
} catch (std::exception& error) {
192192
Cerr << error.what();
193193
}
194194
}
195195

196196
std::cout << std::endl << "Bye" << std::endl;
197197
}
198198

199-
}
200-
}
199+
} // namespace NYdb::NConsoleClient

ydb/public/lib/ydb_cli/commands/interactive/interactive_cli.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,17 @@
44

55
#include <ydb/public/lib/ydb_cli/common/command.h>
66

7-
namespace NYdb {
8-
namespace NConsoleClient {
7+
namespace NYdb::NConsoleClient {
98

10-
class TInteractiveCLI
11-
{
9+
class TInteractiveCLI {
1210
public:
13-
TInteractiveCLI(TClientCommand::TConfig & config, std::string prompt);
11+
TInteractiveCLI(TClientCommand::TConfig& config, std::string prompt);
1412

1513
void Run();
1614

1715
private:
18-
TClientCommand::TConfig & Config;
16+
TClientCommand::TConfig& Config;
1917
std::string Prompt;
2018
};
2119

22-
}
23-
}
20+
} // namespace NYdb::NConsoleClient

ydb/public/lib/ydb_cli/commands/interactive/line_reader.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,26 @@
1010

1111
#include <contrib/restricted/patched/replxx/include/replxx.hxx>
1212

13-
namespace NYdb {
14-
namespace NConsoleClient {
13+
namespace NYdb::NConsoleClient {
1514

16-
namespace
17-
{
15+
namespace {
1816

19-
class FileHandlerLockGuard
20-
{
17+
class FileHandlerLockGuard {
2118
public:
22-
FileHandlerLockGuard(TFileHandle * handle)
19+
FileHandlerLockGuard(TFileHandle* handle)
2320
: Handle(handle)
24-
{}
21+
{
22+
}
2523

2624
~FileHandlerLockGuard() {
2725
Handle->Flock(LOCK_UN);
2826
}
27+
2928
private:
30-
TFileHandle * Handle = nullptr;
29+
TFileHandle* Handle = nullptr;
3130
};
3231

33-
std::optional<FileHandlerLockGuard> LockFile(TFileHandle & fileHandle) {
32+
std::optional<FileHandlerLockGuard> LockFile(TFileHandle& fileHandle) {
3433
if (fileHandle.Flock(LOCK_EX) != 0) {
3534
return {};
3635
}
@@ -42,15 +41,14 @@ replxx::Replxx::Color ReplxxColorOf(NSQLComplete::ECandidateKind /* kind */) {
4241
return replxx::Replxx::Color::DEFAULT;
4342
}
4443

45-
class TLineReader : public ILineReader
46-
{
44+
class TLineReader: public ILineReader {
4745
public:
4846
TLineReader(std::string prompt, std::string historyFilePath);
4947

5048
std::optional<std::string> ReadLine() override;
5149

5250
private:
53-
void AddToHistory(const std::string & line);
51+
void AddToHistory(const std::string& line);
5452

5553
std::string Prompt;
5654
std::string HistoryFilePath;
@@ -67,7 +65,7 @@ TLineReader::TLineReader(std::string prompt, std::string historyFilePath)
6765
{
6866
Rx.install_window_change_handler();
6967

70-
auto completion_callback = [this](const std::string & prefix, size_t contextLen) {
68+
auto completion_callback = [this](const std::string& prefix, size_t contextLen) {
7169
auto completion = CompletionEngine->Complete({
7270
.Text = prefix,
7371
.CursorPosition = prefix.length(),
@@ -114,26 +112,28 @@ TLineReader::TLineReader(std::string prompt, std::string historyFilePath)
114112

115113
std::optional<std::string> TLineReader::ReadLine() {
116114
while (true) {
117-
const auto * status = Rx.input(Prompt.c_str());
115+
const auto* status = Rx.input(Prompt.c_str());
118116

119117
if (status == nullptr) {
120-
if (errno == EAGAIN)
118+
if (errno == EAGAIN) {
121119
continue;
120+
}
122121

123122
return {};
124123
}
125124

126125
std::string line = status;
127-
while (!line.empty() && std::isspace(line.back()))
126+
while (!line.empty() && std::isspace(line.back())) {
128127
line.pop_back();
128+
}
129129

130130
AddToHistory(line);
131131

132132
return line;
133133
}
134134
}
135135

136-
void TLineReader::AddToHistory(const std::string & line) {
136+
void TLineReader::AddToHistory(const std::string& line) {
137137
Rx.history_add(line);
138138

139139
auto fileLockGuard = LockFile(HistoryFileHandle);
@@ -147,11 +147,10 @@ void TLineReader::AddToHistory(const std::string & line) {
147147
}
148148
}
149149

150-
}
150+
} // namespace
151151

152152
std::unique_ptr<ILineReader> CreateLineReader(std::string prompt, std::string historyFilePath) {
153153
return std::make_unique<TLineReader>(std::move(prompt), std::move(historyFilePath));
154154
}
155155

156-
}
157-
}
156+
} // namespace NYdb::NConsoleClient

ydb/public/lib/ydb_cli/commands/interactive/line_reader.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@
44
#include <optional>
55
#include <string>
66

7-
namespace NYdb {
8-
namespace NConsoleClient {
7+
namespace NYdb::NConsoleClient {
98

109
class ILineReader {
1110
public:
1211
virtual std::optional<std::string> ReadLine() = 0;
1312

1413
virtual ~ILineReader() = default;
15-
1614
};
1715

1816
std::unique_ptr<ILineReader> CreateLineReader(std::string prompt, std::string historyFilePath);
1917

20-
}
21-
}
18+
} // namespace NYdb::NConsoleClient

ydb/public/lib/ydb_cli/commands/interactive/yql_highlight.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,5 @@ namespace NYdb {
7070
TParsedTokenList Tokens;
7171
};
7272

73-
}
74-
}
73+
} // namespace NConsoleClient
74+
} // namespace NYdb

ydb/public/lib/ydb_cli/commands/interactive/yql_highlight_ut.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,4 +365,4 @@ Y_UNIT_TEST_SUITE(YqlHighlightTests) {
365365
" "
366366
"kkkkkk no ovvvo ss kk kkkkko"));
367367
}
368-
}
368+
} // Y_UNIT_TEST_SUITE(YqlHighlightTests)

ydb/public/lib/ydb_cli/commands/interactive/yql_position.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ namespace NYdb {
3838
{
3939
}
4040

41-
}
42-
}
41+
} // namespace NConsoleClient
42+
} // namespace NYdb

ydb/public/lib/ydb_cli/commands/interactive/yql_position.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ namespace NYdb {
2727
TVector<ui32> SymbolsCountBeforeLine;
2828
};
2929

30-
}
31-
}
30+
} // namespace NConsoleClient
31+
} // namespace NYdb

0 commit comments

Comments
 (0)