diff options
author | Victor Smirnov <53015676+vityaman@users.noreply.github.com> | 2025-03-03 16:04:42 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-03 13:04:42 +0000 |
commit | b3e0a1f24ae53d099fd4f2886e346403a73dae6c (patch) | |
tree | 5e5a02257059f1e92378b116e7f7a47f47a22869 | |
parent | 5a903729c5ef88ab64ea5728a2ef4d33b81c8369 (diff) | |
download | ydb-b3e0a1f24ae53d099fd4f2886e346403a73dae6c.tar.gz |
#9056 Format module commands/interactive (#15212)
Signed-off-by: vityaman <vityaman.dev@yandex.ru>
8 files changed, 50 insertions, 58 deletions
diff --git a/ydb/public/lib/ydb_cli/commands/interactive/interactive_cli.cpp b/ydb/public/lib/ydb_cli/commands/interactive/interactive_cli.cpp index 8ec47b0e10..20524b7345 100644 --- a/ydb/public/lib/ydb_cli/commands/interactive/interactive_cli.cpp +++ b/ydb/public/lib/ydb_cli/commands/interactive/interactive_cli.cpp @@ -11,9 +11,7 @@ #include <ydb/public/lib/ydb_cli/commands/ydb_service_table.h> #include <ydb/public/lib/ydb_cli/commands/ydb_sql.h> -namespace NYdb { -namespace NConsoleClient { - +namespace NYdb::NConsoleClient { namespace { @@ -43,13 +41,14 @@ public: private: std::string_view Input; - const char * Position = nullptr; + const char* Position = nullptr; }; Lexer::Lexer(std::string_view input) : Input(input) , Position(Input.data()) -{} +{ +} std::optional<Token> Lexer::GetNextToken() { while (Position < Input.end() && std::isspace(*Position)) { @@ -60,7 +59,7 @@ std::optional<Token> Lexer::GetNextToken() { return {}; } - const char * tokenStart = Position; + const char* tokenStart = Position; if (IsSeparatedTokenSymbol(*Position)) { ++Position; } else { @@ -92,7 +91,7 @@ struct InteractiveCLIState { NTable::ECollectQueryStatsMode CollectStatsMode = NTable::ECollectQueryStatsMode::None; }; -std::optional<NTable::ECollectQueryStatsMode> TryParseCollectStatsMode(const std::vector<Token> & tokens) { +std::optional<NTable::ECollectQueryStatsMode> TryParseCollectStatsMode(const std::vector<Token>& tokens) { size_t tokensSize = tokens.size(); if (tokensSize > 4) { @@ -107,7 +106,7 @@ std::optional<NTable::ECollectQueryStatsMode> TryParseCollectStatsMode(const std return statsMode; } -void ParseSetCommand(const std::vector<Token> & tokens, InteractiveCLIState & interactiveCLIState) { +void ParseSetCommand(const std::vector<Token>& tokens, InteractiveCLIState& interactiveCLIState) { if (tokens.size() == 1) { Cerr << "Missing variable name for \"SET\" special command." << Endl; } else if (tokens.size() == 2 || tokens[2].data != "=") { @@ -123,12 +122,13 @@ void ParseSetCommand(const std::vector<Token> & tokens, InteractiveCLIState & in } } -} +} // namespace -TInteractiveCLI::TInteractiveCLI(TClientCommand::TConfig & config, std::string prompt) +TInteractiveCLI::TInteractiveCLI(TClientCommand::TConfig& config, std::string prompt) : Config(config) , Prompt(std::move(prompt)) -{} +{ +} void TInteractiveCLI::Run() { TFsPath homeDirPath(HomeDir); @@ -139,7 +139,7 @@ void TInteractiveCLI::Run() { while (auto lineOptional = lineReader->ReadLine()) { - auto & line = *lineOptional; + auto& line = *lineOptional; if (line.empty()) { continue; } @@ -184,11 +184,11 @@ void TInteractiveCLI::Run() { sqlCommand.SetCollectStatsMode(std::move(queryStatsMode)); sqlCommand.SetSyntax("yql"); sqlCommand.Run(Config); - } catch (NStatusHelpers::TYdbErrorException &error) { + } catch (NStatusHelpers::TYdbErrorException& error) { Cerr << error; - } catch (yexception & error) { + } catch (yexception& error) { Cerr << error; - } catch (std::exception & error) { + } catch (std::exception& error) { Cerr << error.what(); } } @@ -196,5 +196,4 @@ void TInteractiveCLI::Run() { std::cout << std::endl << "Bye" << std::endl; } -} -} +} // namespace NYdb::NConsoleClient diff --git a/ydb/public/lib/ydb_cli/commands/interactive/interactive_cli.h b/ydb/public/lib/ydb_cli/commands/interactive/interactive_cli.h index 3c03729b12..d9350a6ef0 100644 --- a/ydb/public/lib/ydb_cli/commands/interactive/interactive_cli.h +++ b/ydb/public/lib/ydb_cli/commands/interactive/interactive_cli.h @@ -4,20 +4,17 @@ #include <ydb/public/lib/ydb_cli/common/command.h> -namespace NYdb { -namespace NConsoleClient { +namespace NYdb::NConsoleClient { -class TInteractiveCLI -{ +class TInteractiveCLI { public: - TInteractiveCLI(TClientCommand::TConfig & config, std::string prompt); + TInteractiveCLI(TClientCommand::TConfig& config, std::string prompt); void Run(); private: - TClientCommand::TConfig & Config; + TClientCommand::TConfig& Config; std::string Prompt; }; -} -} +} // namespace NYdb::NConsoleClient diff --git a/ydb/public/lib/ydb_cli/commands/interactive/line_reader.cpp b/ydb/public/lib/ydb_cli/commands/interactive/line_reader.cpp index 3020bba0dd..9726dcb664 100644 --- a/ydb/public/lib/ydb_cli/commands/interactive/line_reader.cpp +++ b/ydb/public/lib/ydb_cli/commands/interactive/line_reader.cpp @@ -10,27 +10,26 @@ #include <contrib/restricted/patched/replxx/include/replxx.hxx> -namespace NYdb { -namespace NConsoleClient { +namespace NYdb::NConsoleClient { -namespace -{ +namespace { -class FileHandlerLockGuard -{ +class FileHandlerLockGuard { public: - FileHandlerLockGuard(TFileHandle * handle) + FileHandlerLockGuard(TFileHandle* handle) : Handle(handle) - {} + { + } ~FileHandlerLockGuard() { Handle->Flock(LOCK_UN); } + private: - TFileHandle * Handle = nullptr; + TFileHandle* Handle = nullptr; }; -std::optional<FileHandlerLockGuard> LockFile(TFileHandle & fileHandle) { +std::optional<FileHandlerLockGuard> LockFile(TFileHandle& fileHandle) { if (fileHandle.Flock(LOCK_EX) != 0) { return {}; } @@ -42,15 +41,14 @@ replxx::Replxx::Color ReplxxColorOf(NSQLComplete::ECandidateKind /* kind */) { return replxx::Replxx::Color::DEFAULT; } -class TLineReader : public ILineReader -{ +class TLineReader: public ILineReader { public: TLineReader(std::string prompt, std::string historyFilePath); std::optional<std::string> ReadLine() override; private: - void AddToHistory(const std::string & line); + void AddToHistory(const std::string& line); std::string Prompt; std::string HistoryFilePath; @@ -67,7 +65,7 @@ TLineReader::TLineReader(std::string prompt, std::string historyFilePath) { Rx.install_window_change_handler(); - auto completion_callback = [this](const std::string & prefix, size_t contextLen) { + auto completion_callback = [this](const std::string& prefix, size_t contextLen) { auto completion = CompletionEngine->Complete({ .Text = prefix, .CursorPosition = prefix.length(), @@ -114,18 +112,20 @@ TLineReader::TLineReader(std::string prompt, std::string historyFilePath) std::optional<std::string> TLineReader::ReadLine() { while (true) { - const auto * status = Rx.input(Prompt.c_str()); + const auto* status = Rx.input(Prompt.c_str()); if (status == nullptr) { - if (errno == EAGAIN) + if (errno == EAGAIN) { continue; + } return {}; } std::string line = status; - while (!line.empty() && std::isspace(line.back())) + while (!line.empty() && std::isspace(line.back())) { line.pop_back(); + } AddToHistory(line); @@ -133,7 +133,7 @@ std::optional<std::string> TLineReader::ReadLine() { } } -void TLineReader::AddToHistory(const std::string & line) { +void TLineReader::AddToHistory(const std::string& line) { Rx.history_add(line); auto fileLockGuard = LockFile(HistoryFileHandle); @@ -147,11 +147,10 @@ void TLineReader::AddToHistory(const std::string & line) { } } -} +} // namespace std::unique_ptr<ILineReader> CreateLineReader(std::string prompt, std::string historyFilePath) { return std::make_unique<TLineReader>(std::move(prompt), std::move(historyFilePath)); } -} -} +} // namespace NYdb::NConsoleClient diff --git a/ydb/public/lib/ydb_cli/commands/interactive/line_reader.h b/ydb/public/lib/ydb_cli/commands/interactive/line_reader.h index e16cea1969..830cd9f56c 100644 --- a/ydb/public/lib/ydb_cli/commands/interactive/line_reader.h +++ b/ydb/public/lib/ydb_cli/commands/interactive/line_reader.h @@ -4,18 +4,15 @@ #include <optional> #include <string> -namespace NYdb { -namespace NConsoleClient { +namespace NYdb::NConsoleClient { class ILineReader { public: virtual std::optional<std::string> ReadLine() = 0; virtual ~ILineReader() = default; - }; std::unique_ptr<ILineReader> CreateLineReader(std::string prompt, std::string historyFilePath); -} -} +} // namespace NYdb::NConsoleClient diff --git a/ydb/public/lib/ydb_cli/commands/interactive/yql_highlight.h b/ydb/public/lib/ydb_cli/commands/interactive/yql_highlight.h index b7fd7ad4c8..14fa76a5bb 100644 --- a/ydb/public/lib/ydb_cli/commands/interactive/yql_highlight.h +++ b/ydb/public/lib/ydb_cli/commands/interactive/yql_highlight.h @@ -70,5 +70,5 @@ namespace NYdb { TParsedTokenList Tokens; }; - } -} + } // namespace NConsoleClient +} // namespace NYdb diff --git a/ydb/public/lib/ydb_cli/commands/interactive/yql_highlight_ut.cpp b/ydb/public/lib/ydb_cli/commands/interactive/yql_highlight_ut.cpp index ac8f178119..037556754d 100644 --- a/ydb/public/lib/ydb_cli/commands/interactive/yql_highlight_ut.cpp +++ b/ydb/public/lib/ydb_cli/commands/interactive/yql_highlight_ut.cpp @@ -365,4 +365,4 @@ Y_UNIT_TEST_SUITE(YqlHighlightTests) { " " "kkkkkk no ovvvo ss kk kkkkko")); } -} +} // Y_UNIT_TEST_SUITE(YqlHighlightTests) diff --git a/ydb/public/lib/ydb_cli/commands/interactive/yql_position.cpp b/ydb/public/lib/ydb_cli/commands/interactive/yql_position.cpp index 02008fc44d..79f9bd674a 100644 --- a/ydb/public/lib/ydb_cli/commands/interactive/yql_position.cpp +++ b/ydb/public/lib/ydb_cli/commands/interactive/yql_position.cpp @@ -38,5 +38,5 @@ namespace NYdb { { } - } -} + } // namespace NConsoleClient +} // namespace NYdb diff --git a/ydb/public/lib/ydb_cli/commands/interactive/yql_position.h b/ydb/public/lib/ydb_cli/commands/interactive/yql_position.h index 424b33ab19..5f6781b9c1 100644 --- a/ydb/public/lib/ydb_cli/commands/interactive/yql_position.h +++ b/ydb/public/lib/ydb_cli/commands/interactive/yql_position.h @@ -27,5 +27,5 @@ namespace NYdb { TVector<ui32> SymbolsCountBeforeLine; }; - } -} + } // namespace NConsoleClient +} // namespace NYdb |