Skip to content

Commit 7402c4e

Browse files
committed
Print options tree
1 parent 0a8b0d9 commit 7402c4e

File tree

7 files changed

+50
-32
lines changed

7 files changed

+50
-32
lines changed

Diff for: ydb/core/driver_lib/cli_base/cli_cmds_root.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void TClientCommandRootKikimrBase::Config(TConfig& config) {
5858
NColorizer::TColors colors = NColorizer::AutoColors(Cout);
5959
stream << " -s <[protocol://]host[:port]> [options] <subcommand>" << Endl << Endl
6060
<< colors.BoldColor() << "Subcommands" << colors.OldColor() << ":" << Endl;
61-
RenderCommandsDescription(stream, colors);
61+
RenderCommandDescription(stream, config.HelpCommandVerbosiltyLevel > 1, colors);
6262
opts.SetCmdLineDescr(stream.Str());
6363
}
6464

Diff for: ydb/core/driver_lib/cli_utils/cli_cmds_root.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ TString NewClientCommandsDescription(const TString& name, std::shared_ptr<TModul
8383
NColorizer::TColors colors = NColorizer::AutoColors(Cout);
8484
stream << " [options] <subcommand>" << Endl << Endl
8585
<< colors.BoldColor() << "Subcommands" << colors.OldColor() << ":" << Endl;
86-
commandsRoot->RenderCommandsDescription(stream, colors);
86+
commandsRoot->RenderCommandDescription(stream, false, colors);
8787
return stream.Str();
8888
}
8989

Diff for: ydb/core/kqp/tests/tpch/commands.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void TClientCommandTpchRoot::Config(TConfig& config) {
4444
NColorizer::TColors colors = NColorizer::AutoColors(Cout);
4545
stream << " [options...] <subcommand>" << Endl << Endl
4646
<< colors.BoldColor() << "Subcommands" << colors.OldColor() << ":" << Endl;
47-
RenderCommandsDescription(stream, colors);
47+
RenderCommandDescription(stream, config.HelpCommandVerbosiltyLevel > 1, colors);
4848
config.Opts->SetCmdLineDescr(stream.Str());
4949
}
5050

Diff for: ydb/public/lib/ydb_cli/commands/ydb_admin.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class TCommandDatabase : public TClientCommandTree {
3737
}
3838
};
3939

40-
TCommandDatabaseDump::TCommandDatabaseDump()
41-
: TYdbReadOnlyCommand("dump", {}, "Dump database into local directory")
40+
TCommandDatabaseDump::TCommandDatabaseDump()
41+
: TYdbReadOnlyCommand("dump", {}, "Dump database into local directory")
4242
{}
4343

4444
void TCommandDatabaseDump::Config(TConfig& config) {
@@ -66,8 +66,8 @@ int TCommandDatabaseDump::Run(TConfig& config) {
6666
return EXIT_SUCCESS;
6767
}
6868

69-
TCommandDatabaseRestore::TCommandDatabaseRestore()
70-
: TYdbCommand("restore", {}, "Restore database from local dump")
69+
TCommandDatabaseRestore::TCommandDatabaseRestore()
70+
: TYdbCommand("restore", {}, "Restore database from local dump")
7171
{}
7272

7373
void TCommandDatabaseRestore::Config(TConfig& config) {
@@ -135,7 +135,7 @@ void TCommandAdmin::Config(TConfig& config) {
135135
stream << Endl << Endl
136136
<< colors.BoldColor() << "Description" << colors.OldColor() << ": " << Description << Endl << Endl
137137
<< colors.BoldColor() << "Subcommands" << colors.OldColor() << ":" << Endl;
138-
RenderCommandsDescription(stream, colors);
138+
RenderCommandDescription(stream, config.HelpCommandVerbosiltyLevel > 1, colors);
139139
stream << Endl;
140140
PrintParentOptions(stream, config, colors);
141141
config.Opts->SetCmdLineDescr(stream.Str());

Diff for: ydb/public/lib/ydb_cli/commands/ydb_root_common.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ void TClientCommandRootCommon::Config(TConfig& config) {
323323
NColorizer::TColors colors = NColorizer::AutoColors(Cout);
324324
stream << " [options...] <subcommand>" << Endl << Endl
325325
<< colors.BoldColor() << "Subcommands" << colors.OldColor() << ":" << Endl;
326-
RenderCommandsDescription(stream, colors);
326+
RenderCommandDescription(stream, config.HelpCommandVerbosiltyLevel > 1, colors);
327327
stream << Endl << Endl << colors.BoldColor() << "Commands in " << colors.Red() << colors.BoldColor() << "admin" << colors.OldColor() << colors.BoldColor() << " subtree may treat global flags and profile differently, see corresponding help" << colors.OldColor() << Endl;
328328
opts.SetCmdLineDescr(stream.Str());
329329

Diff for: ydb/public/lib/ydb_cli/common/command.cpp

+31-18
Original file line numberDiff line numberDiff line change
@@ -303,21 +303,24 @@ void TClientCommand::SetFreeArgTitle(size_t pos, const TString& title, const TSt
303303
Opts.SetFreeArgTitle(pos, title, help);
304304
}
305305

306-
void TClientCommand::RenderOneCommandDescription(
306+
void TClientCommand::RenderCommandDescription(
307307
TStringStream& stream,
308+
bool renderTree,
308309
const NColorizer::TColors& colors,
309-
RenderEntryType type
310+
RenderEntryType type,
311+
TString prefix
310312
) {
313+
Y_UNUSED(renderTree);
311314
if (Hidden && type != BEGIN) {
312315
return;
313316
}
314-
TString prefix;
315317
if (type == MIDDLE) {
316-
prefix = "├─ ";
318+
prefix += "├─ ";
317319
}
318320
if (type == END) {
319-
prefix = "└─ ";
321+
prefix += "└─ ";
320322
}
323+
321324
TString line = prefix + Name;
322325
stream << prefix << (Dangerous ? colors.Red() : "") << colors.BoldColor() << Name << colors.OldColor();
323326
if (!Description.empty()) {
@@ -389,7 +392,7 @@ void TClientCommandTree::Config(TConfig& config) {
389392
stream << Endl << Endl
390393
<< colors.BoldColor() << "Description" << colors.OldColor() << ": " << Description << Endl << Endl
391394
<< colors.BoldColor() << "Subcommands" << colors.OldColor() << ":" << Endl;
392-
RenderCommandsDescription(stream, colors);
395+
RenderCommandDescription(stream, config.HelpCommandVerbosiltyLevel > 1, colors);
393396
stream << Endl;
394397
PrintParentOptions(stream, config, colors);
395398
config.Opts->SetCmdLineDescr(stream.Str());
@@ -459,22 +462,32 @@ bool TClientCommandTree::HasOptionsToShow() {
459462
return false;
460463
}
461464

462-
void TClientCommandTree::RenderCommandsDescription(
465+
void TClientCommandTree::RenderCommandDescription(
463466
TStringStream& stream,
464-
const NColorizer::TColors& colors
467+
bool renderTree,
468+
const NColorizer::TColors& colors,
469+
RenderEntryType type,
470+
TString prefix
465471
) {
466-
TClientCommand::RenderOneCommandDescription(stream, colors, BEGIN);
467-
468-
TVector<TClientCommand*> VisibleSubCommands;
469-
for (auto& [_, command] : SubCommands) {
470-
if (command->Visible) {
471-
VisibleSubCommands.push_back(command.get());
472+
TClientCommand::RenderCommandDescription(stream, false, colors, type, prefix);
473+
if (type == BEGIN || renderTree) {
474+
if (type == MIDDLE) {
475+
prefix += "";
476+
}
477+
if (type == END) {
478+
prefix += " ";
479+
}
480+
TVector<TClientCommand*> visibleSubCommands;
481+
for (auto& [_, command] : SubCommands) {
482+
if (command->Visible) {
483+
visibleSubCommands.push_back(command.get());
484+
}
472485
}
473-
}
474486

475-
for (auto it = VisibleSubCommands.begin(); it != VisibleSubCommands.end(); ++it) {
476-
bool lastCommand = (std::next(it) == VisibleSubCommands.end());
477-
(*it)->RenderOneCommandDescription(stream, colors, lastCommand ? END : MIDDLE);
487+
for (auto it = visibleSubCommands.begin(); it != visibleSubCommands.end(); ++it) {
488+
bool lastCommand = (std::next(it) == visibleSubCommands.end());
489+
(*it)->RenderCommandDescription(stream, renderTree, colors, lastCommand ? END : MIDDLE, prefix);
490+
}
478491
}
479492
}
480493

Diff for: ydb/public/lib/ydb_cli/common/command.h

+10-5
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,12 @@ class TClientCommand {
356356
END
357357
};
358358

359-
void RenderOneCommandDescription(
359+
virtual void RenderCommandDescription(
360360
TStringStream& stream,
361+
bool renderTree,
361362
const NColorizer::TColors& colors = NColorizer::TColors(false),
362-
RenderEntryType type = BEGIN
363+
RenderEntryType type = BEGIN,
364+
TString prefix = {}
363365
);
364366

365367
void Hide();
@@ -394,10 +396,13 @@ class TClientCommandTree : public TClientCommand {
394396
void AddHiddenCommand(std::unique_ptr<TClientCommand> command);
395397
void AddDangerousCommand(std::unique_ptr<TClientCommand> command);
396398
virtual void Prepare(TConfig& config) override;
397-
void RenderCommandsDescription(
399+
void RenderCommandDescription(
398400
TStringStream& stream,
399-
const NColorizer::TColors& colors = NColorizer::TColors(false)
400-
);
401+
bool renderTree,
402+
const NColorizer::TColors& colors = NColorizer::TColors(false),
403+
RenderEntryType type = BEGIN,
404+
TString prefix = {}
405+
) override;
401406
virtual void SetFreeArgs(TConfig& config);
402407
bool HasSelectedCommand() const { return SelectedCommand; }
403408

0 commit comments

Comments
 (0)