diff options
author | brgayazov <bulat@ydb.tech> | 2023-04-27 11:16:27 +0300 |
---|---|---|
committer | brgayazov <bulat@ydb.tech> | 2023-04-27 11:16:27 +0300 |
commit | 0fc70ff9c8a58c7bc4eceb15e1b0bb55375963b0 (patch) | |
tree | 052bb7c4e192840dae0b7fbbcad05602c724e040 | |
parent | c46268f9104183574c33c78e3407ff245d3968c0 (diff) | |
download | ydb-0fc70ff9c8a58c7bc4eceb15e1b0bb55375963b0.tar.gz |
Changed output of command tree on top level output
-rw-r--r-- | ydb/public/lib/ydb_cli/common/command.cpp | 36 | ||||
-rw-r--r-- | ydb/public/lib/ydb_cli/common/command.h | 19 |
2 files changed, 23 insertions, 32 deletions
diff --git a/ydb/public/lib/ydb_cli/common/command.cpp b/ydb/public/lib/ydb_cli/common/command.cpp index 250089e4f9..5eda961592 100644 --- a/ydb/public/lib/ydb_cli/common/command.cpp +++ b/ydb/public/lib/ydb_cli/common/command.cpp @@ -260,29 +260,18 @@ void TClientCommand::SetFreeArgTitle(size_t pos, const TString& title, const TSt Opts.SetFreeArgTitle(pos, title, help); } -TString TClientCommand::Ends2Prefix(const std::basic_string<bool>& ends) { - TString prefix; - if (!ends.empty()) { - for (auto it = ends.begin();;) { - bool s = *it; - ++it; - if (it == ends.end()) { - prefix += s ? "└─ " : "├─ "; - break; - } else { - prefix += s ? " " : "│ "; - } - } - } - return prefix; -} - -void TClientCommand::RenderCommandsDescription( +void TClientCommand::RenderOneCommandDescription( TStringStream& stream, const NColorizer::TColors& colors, - const std::basic_string<bool>& ends + RenderEntryType type ) { - TString prefix = Ends2Prefix(ends); + TString prefix; + if (type == MIDDLE) { + prefix = "├─ "; + } + if (type == END) { + prefix = "└─ "; + } TString line = prefix + Name; stream << prefix << colors.BoldColor() << Name << colors.OldColor(); if (!Description.empty()) { @@ -399,13 +388,12 @@ bool TClientCommandTree::HasOptionsToShow() { void TClientCommandTree::RenderCommandsDescription( TStringStream& stream, - const NColorizer::TColors& colors, - const std::basic_string<bool>& ends + const NColorizer::TColors& colors ) { - TClientCommand::RenderCommandsDescription(stream, colors, ends); + TClientCommand::RenderOneCommandDescription(stream, colors, BEGIN); for (auto it = SubCommands.begin(); it != SubCommands.end(); ++it) { bool lastCommand = (std::next(it) == SubCommands.end()); - it->second->RenderCommandsDescription(stream, colors, ends + lastCommand); + it->second->RenderOneCommandDescription(stream, colors, lastCommand ? END : MIDDLE); } } diff --git a/ydb/public/lib/ydb_cli/common/command.h b/ydb/public/lib/ydb_cli/common/command.h index 4ce1aad157..5fb6c3dab0 100644 --- a/ydb/public/lib/ydb_cli/common/command.h +++ b/ydb/public/lib/ydb_cli/common/command.h @@ -268,10 +268,16 @@ public: virtual void Prepare(TConfig& config); virtual int ValidateAndRun(TConfig& config); - virtual void RenderCommandsDescription( + enum RenderEntryType { + BEGIN, + MIDDLE, + END + }; + + void RenderOneCommandDescription( TStringStream& stream, const NColorizer::TColors& colors = NColorizer::TColors(false), - const std::basic_string<bool>& ends = std::basic_string<bool>() + RenderEntryType type = BEGIN ); protected: @@ -293,8 +299,6 @@ private: void CheckForExecutableOptions(TConfig& config); constexpr static int DESCRIPTION_ALIGNMENT = 28; - - static TString Ends2Prefix(const std::basic_string<bool>& ends); }; class TClientCommandTree : public TClientCommand { @@ -306,11 +310,10 @@ public: TClientCommandTree(const TString& name, const std::initializer_list<TString>& aliases = std::initializer_list<TString>(), const TString& description = TString()); void AddCommand(std::unique_ptr<TClientCommand> command); virtual void Prepare(TConfig& config) override; - virtual void RenderCommandsDescription( + void RenderCommandsDescription( TStringStream& stream, - const NColorizer::TColors& colors = NColorizer::TColors(false), - const std::basic_string<bool>& ends = std::basic_string<bool>() - ) override; + const NColorizer::TColors& colors = NColorizer::TColors(false) + ); virtual void SetFreeArgs(TConfig& config); protected: |