Skip to content

Refactor ydb cli options #15800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ydb/apps/ydb/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* YDB CLI help message improvements. Different display for detailed help and brief help.
* Support coordination nodes in `ydb scheme rmdir --recursive`.
* Fixed return code of command `ydb workload * run --check-canonical` for the case when benchmark query results differ from canonical ones.

Expand Down
7 changes: 5 additions & 2 deletions ydb/apps/ydb/commands/ydb_root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ void TClientCommandRoot::SetCredentialsGetter(TConfig& config) {
if (config.UseMetadataCredentials) {
return CreateIamCredentialsProviderFactory();
}
if (config.SaKeyParams) {
return CreateIamJwtParamsCredentialsProviderFactory(
{ {.Endpoint = config.IamEndpoint}, config.SaKeyParams });
}
if (config.SaKeyFile) {
return CreateIamJwtFileCredentialsProviderFactory(
{ {.Endpoint = config.IamEndpoint}, config.SaKeyFile });
Expand Down Expand Up @@ -77,8 +81,7 @@ namespace {
void TYdbClientCommandRoot::Config(TConfig& config) {
TClientCommandRoot::Config(config);

NLastGetopt::TOpts& opts = *config.Opts;
RemoveOption(opts, "svnrevision");
RemoveOption(config.Opts->GetOpts(), "svnrevision");
}

int TYdbClientCommandRoot::Run(TConfig& config) {
Expand Down
43 changes: 20 additions & 23 deletions ydb/apps/ydb/ut/parse_command_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,17 +525,16 @@ Y_UNIT_TEST_SUITE(ParseOptionsTest) {
{"YDB_PASSWORD", "pwd"},
});

// TODO: make these options mutually exclusive
// ExpectFail();
// RunCli({
// "-v",
// "-e", GetEndpoint(),
// "-d", GetDatabase(),
// "--user", "test-user",
// "--no-password",
// "--password-file", passwordFile,
// "scheme", "ls",
// });
ExpectFail();
RunCli({
"-v",
"-e", GetEndpoint(),
"-d", GetDatabase(),
"--user", "test-user",
"--no-password",
"--password-file", passwordFile,
"scheme", "ls",
});

TString profile = fmt::format(R"yaml(
profiles:
Expand Down Expand Up @@ -636,18 +635,16 @@ Y_UNIT_TEST_SUITE(ParseOptionsTest) {
{},
profile);

// TODO: validate that there is no ambiguity in setting passwords
// ExpectFail();
// RunCli({
// "-v",
// "-p", "test_profile_with_both_passwords",
// "scheme", "ls",
// },
// {},
// profile);

// TODO: Fix this case
//ExpectUserAndPassword("user_no_password", "", "no-password-token");
ExpectFail();
RunCli({
"-v",
"-p", "test_profile_with_both_passwords",
"scheme", "ls",
},
{},
profile);

ExpectUserAndPassword("user_no_password", "", "no-password-token");
RunCli({
"-v",
"-p", "test_profile_without_password",
Expand Down
24 changes: 12 additions & 12 deletions ydb/core/driver_lib/cli_base/cli_cmds_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class TClientCommandSchemaExec : public TClientCommandBase {
virtual void Config(TConfig& config) override {
TClientCommand::Config(config);
ReturnTxId = false;
config.Opts->AddLongOption('t', "txid", "Print TxId").NoArgument().SetFlag(&ReturnTxId);
config.Opts->AddLongOption('t', "txid", "Print TxId").StoreTrue(&ReturnTxId);
config.SetFreeArgsNum(1);
SetFreeArgTitle(0, "<SCHEMA-PROTO>", "Schema protobuf or file with schema protobuf");
}
Expand Down Expand Up @@ -205,14 +205,14 @@ class TClientCommandSchemaDescribe : public TClientCommand {
Boundaries = false;
config.SetFreeArgsNum(1);
SetFreeArgTitle(0, "<PATH>", "Schema path or pathId (e.g. 72075186232623600/1225)");
config.Opts->AddLongOption('t', "tree", "Show schema path tree").NoArgument().SetFlag(&Tree);
config.Opts->AddLongOption('d', "details", "Show detailed information (like columns in a table)").NoArgument().SetFlag(&Details);
config.Opts->AddLongOption('a', "acl", "Show owner and acl information").NoArgument().SetFlag(&AccessRights);
config.Opts->AddLongOption('e', "effacl", "Show effective acl information").NoArgument().SetFlag(&AccessRightsEffective);
config.Opts->AddLongOption('b', "backup", "Show backup information").NoArgument().SetFlag(&BackupInfo);
config.Opts->AddLongOption('P', "protobuf", "Debug print all info as is").NoArgument().SetFlag(&Protobuf);
config.Opts->AddLongOption('s', "stats", "Return partition stats").NoArgument().SetFlag(&PartitionStats);
config.Opts->AddLongOption("boundaries", "Return boundaries").NoArgument().SetFlag(&Boundaries);
config.Opts->AddLongOption('t', "tree", "Show schema path tree").StoreTrue(&Tree);
config.Opts->AddLongOption('d', "details", "Show detailed information (like columns in a table)").StoreTrue(&Details);
config.Opts->AddLongOption('a', "acl", "Show owner and acl information").StoreTrue(&AccessRights);
config.Opts->AddLongOption('e', "effacl", "Show effective acl information").StoreTrue(&AccessRightsEffective);
config.Opts->AddLongOption('b', "backup", "Show backup information").StoreTrue(&BackupInfo);
config.Opts->AddLongOption('P', "protobuf", "Debug print all info as is").StoreTrue(&Protobuf);
config.Opts->AddLongOption('s', "stats", "Return partition stats").StoreTrue(&PartitionStats);
config.Opts->AddLongOption("boundaries", "Return boundaries").StoreTrue(&Boundaries);
}

virtual void Parse(TConfig& config) override {
Expand Down Expand Up @@ -581,8 +581,8 @@ class TClientCommandSchemaChown : public TClientCommand {
SetFreeArgTitle(0, "<USER>", "User");
SetFreeArgTitle(1, "<PATH>", "Full pathname of an object (e.g. /ru/home/user/mydb/test1/test2).\n"
" Or short pathname if profile path is set (e.g. test1/test2).");
config.Opts->AddLongOption('R', "recursive", "Change owner on schema objects recursively").NoArgument().SetFlag(&Recursive);
config.Opts->AddLongOption('v', "verbose", "Verbose output").NoArgument().SetFlag(&Verbose);
config.Opts->AddLongOption('R', "recursive", "Change owner on schema objects recursively").StoreTrue(&Recursive);
config.Opts->AddLongOption('v', "verbose", "Verbose output").StoreTrue(&Verbose);
}

TString Owner;
Expand Down Expand Up @@ -1318,7 +1318,7 @@ class TClientCommandDbExec : public TClientCommandBase {
config.SetFreeArgsNum(1, 2);
SetFreeArgTitle(0, "<MINIKQL>", "Text MiniKQL");
SetFreeArgTitle(1, "<PARAMS>", "Text MiniKQL parameters");
config.Opts->AddLongOption('p', "proto", "MiniKQL parameters are in protobuf format").NoArgument().SetFlag(&Proto);
config.Opts->AddLongOption('p', "proto", "MiniKQL parameters are in protobuf format").StoreTrue(&Proto);
}

virtual void Parse(TConfig& config) override {
Expand Down
4 changes: 2 additions & 2 deletions ydb/core/driver_lib/cli_base/cli_cmds_root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TClientCommandRootKikimrBase::TClientCommandRootKikimrBase(const TString& name)

void TClientCommandRootKikimrBase::Config(TConfig& config) {
TClientCommandRootBase::Config(config);
NLastGetopt::TOpts& opts = *config.Opts;
NLastGetopt::TOpts& opts = config.Opts->GetOpts();
opts.AddLongOption('d', "dump", "Dump requests to error log").NoArgument().Hidden().SetFlag(&DumpRequests);

TStringBuilder tokenHelp;
Expand Down Expand Up @@ -58,7 +58,7 @@ void TClientCommandRootKikimrBase::Config(TConfig& config) {
NColorizer::TColors colors = NColorizer::AutoColors(Cout);
stream << " -s <[protocol://]host[:port]> [options] <subcommand>" << Endl << Endl
<< colors.BoldColor() << "Subcommands" << colors.OldColor() << ":" << Endl;
RenderCommandsDescription(stream, colors);
RenderCommandDescription(stream, config.HelpCommandVerbosiltyLevel > 1, colors);
opts.SetCmdLineDescr(stream.Str());
}

Expand Down
20 changes: 10 additions & 10 deletions ydb/core/driver_lib/cli_utils/cli_cmds_cms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class TClientCommandManageRequest : public TCmsClientCommand
} else {
config.SetFreeArgsNum(0);
}
config.Opts->AddLongOption("dry", "Dry run").NoArgument().SetFlag(&DryRun);
config.Opts->AddLongOption("dry", "Dry run").StoreTrue(&DryRun);
}

void Parse(TConfig& config) override
Expand Down Expand Up @@ -278,7 +278,7 @@ class TClientCommandCheckRequest : public TCmsClientCommand
.RequiredArgument("NAME").StoreResult(&User);
config.SetFreeArgsNum(1);
SetFreeArgTitle(0, "<ID>", "Request ID");
config.Opts->AddLongOption("dry", "Dry run").NoArgument().SetFlag(&DryRun);
config.Opts->AddLongOption("dry", "Dry run").StoreTrue(&DryRun);
}

void Parse(TConfig& config) override
Expand Down Expand Up @@ -334,7 +334,7 @@ class TClientCommandWithAction : public TCmsClientCommand {
config.Opts->AddLongOption("duration", "Action duration in minutes")
.Required().RequiredArgument("NUM").StoreResult(&Duration);
config.SetFreeArgsMin(1);
config.Opts->SetFreeArgDefaultTitle("<NAME>", FreeArgDescr(FreeArgField));
config.Opts->GetOpts().SetFreeArgDefaultTitle("<NAME>", FreeArgDescr(FreeArgField));
}

void Parse(TConfig& config) override
Expand Down Expand Up @@ -440,26 +440,26 @@ class TClientCommandMakeRequest : public TClientCommandWithAction {

config.Opts->AddLongOption("user", "User name").Required()
.RequiredArgument("NAME").StoreResult(&User);
config.Opts->AddLongOption("dry", "Dry run").NoArgument().SetFlag(&DryRun);
config.Opts->AddLongOption("dry", "Dry run").StoreTrue(&DryRun);
config.Opts->AddLongOption("reason", "Informational request description")
.RequiredArgument("STRING").StoreResult(&Reason);
config.Opts->AddLongOption("schedule", "Schedule action in CMS if it's disallowed right now")
.NoArgument().SetFlag(&Schedule);
.StoreTrue(&Schedule);
config.Opts->AddLongOption("hours", "Permission duration")
.RequiredArgument("NUM").StoreResult(&Hours);
config.Opts->AddLongOption("minutes", "Permission duration")
.RequiredArgument("NUM").StoreResult(&Minutes);
config.Opts->AddLongOption("tenant-policy", "Policy for computation node restart")
.RequiredArgument("none|default").StoreResult(&TenantPolicy);
config.Opts->AddLongOption("allow-partial", "Allow partial permission")
.NoArgument().SetFlag(&AllowPartial);
.StoreTrue(&AllowPartial);
config.Opts->AddLongOption("availability-mode", "Availability mode")
.RequiredArgument("max|keep|force").DefaultValue("max").StoreResult(&AvailabilityMode);
config.Opts->AddLongOption("evict-vdisks", "Evict vdisks before granting permission(s)")
.NoArgument().SetFlag(&EvictVDisks);
.StoreTrue(&EvictVDisks);
config.Opts->AddLongOption("priority", "Request priority")
.RequiredArgument("NUM").StoreResult(&Priority);

}

void Parse(TConfig& config) override
Expand Down Expand Up @@ -718,7 +718,7 @@ class TClientCommandManageNotification : public TCmsClientCommand
} else {
config.SetFreeArgsNum(0);
}
config.Opts->AddLongOption("dry", "Dry run").NoArgument().SetFlag(&DryRun);
config.Opts->AddLongOption("dry", "Dry run").StoreTrue(&DryRun);
}

void Parse(TConfig& config) override
Expand Down Expand Up @@ -846,7 +846,7 @@ class TClientCommandManagePermission : public TCmsClientCommand
config.Opts->AddLongOption("minutes", "New permission duration")
.RequiredArgument("NUM").StoreResult(&Minutes);
}
config.Opts->AddLongOption("dry", "Dry run").NoArgument().SetFlag(&DryRun);
config.Opts->AddLongOption("dry", "Dry run").StoreTrue(&DryRun);
}

void Parse(TConfig& config) override
Expand Down
6 changes: 2 additions & 4 deletions ydb/core/driver_lib/cli_utils/cli_cmds_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ class TInit : public TClientCommand {

config.Opts->AddLongOption('n', "dry-run", "do not apply updates")
.Optional()
.NoArgument()
.SetFlag(&DryRun);
.StoreTrue(&DryRun);
}

int Run(TConfig& config) override {
Expand Down Expand Up @@ -180,8 +179,7 @@ class TInvoke : public TClientCommand {

config.Opts->AddLongOption('n', "dry-run", "do not apply updates")
.Optional()
.NoArgument()
.SetFlag(&DryRun);
.StoreTrue(&DryRun);
}

int Run(TConfig& config) override {
Expand Down
6 changes: 3 additions & 3 deletions ydb/core/driver_lib/cli_utils/cli_cmds_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class TClientCommandConsoleConfigsUpdate : public TConsoleClientCommand {
virtual void Config(TConfig& config) override {
TConsoleClientCommand::Config(config);
config.Opts->AddLongOption("dry-run", "Execute configure request in dry-run mode")
.NoArgument().SetFlag(&DryRun);
.StoreTrue(&DryRun);
config.Opts->AddLongOption("out-dir", "Output affected configs into specified directory")
.RequiredArgument("PATH").StoreResult(&OutDir);
config.SetFreeArgsNum(1);
Expand Down Expand Up @@ -525,10 +525,10 @@ class TClientCommandConsoleConfigSet : public TConsoleClientCommand {
virtual void Config(TConfig& config) override {
TConsoleClientCommand::Config(config);
config.Opts->AddLongOption("merge", "Merge provided config with the current one")
.NoArgument().SetFlag(&Merge);
.StoreTrue(&Merge);
config.Opts->AddLongOption("merge-overwrite-repeated", "Merge provided config with the current one"
" but overwrite those repeated field which are not empty in provided config")
.NoArgument().SetFlag(&MergeOverwriteRepeated);
.StoreTrue(&MergeOverwriteRepeated);
config.SetFreeArgsNum(1);
SetFreeArgTitle(0, "<CONFIG-PROTO>", "Console config protobuf or file with protobuf");
}
Expand Down
22 changes: 11 additions & 11 deletions ydb/core/driver_lib/cli_utils/cli_cmds_disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ class TClientCommandDiskInfo : public TClientCommand {
.Optional().AppendTo(&MainKeyTmp); // TODO: make required
config.Opts->AddLongOption("master-key", "obsolete: use main-key").RequiredArgument("NUM")
.Optional().AppendTo(&MainKeyTmp); // TODO: remove after migration
config.Opts->AddLongOption('v', "verbose", "output detailed information for debugging").Optional().NoArgument()
.SetFlag(&IsVerbose);
config.Opts->AddLongOption('l', "lock", "lock device before reading disk info").Optional().NoArgument()
.SetFlag(&LockDevice);
config.Opts->AddLongOption('v', "verbose", "output detailed information for debugging").Optional()
.StoreTrue(&IsVerbose);
config.Opts->AddLongOption('l', "lock", "lock device before reading disk info").Optional()
.StoreTrue(&LockDevice);
}

virtual void Parse(TConfig& config) override {
TClientCommand::Parse(config);
Path = config.ParseResult->GetFreeArgs()[0];
// TODO: remove after master->main key migration
bool hasMainOption = config.ParseResult->FindLongOptParseResult("main-key");
bool hasMasterOption = config.ParseResult->FindLongOptParseResult("master-key");
bool hasKOption = config.ParseResult->FindCharOptParseResult('k');
bool hasMainOption = config.ParseResult->Has("main-key");
bool hasMasterOption = config.ParseResult->Has("master-key");
bool hasKOption = config.ParseResult->Has('k');
if (!hasMainOption && !hasMasterOption && !hasKOption)
ythrow yexception() << "missing main-key param";

Expand Down Expand Up @@ -148,7 +148,7 @@ class TClientCommandDiskFormat : public TClientCommand {
config.Opts->AddLongOption('t', "text-message", "text message to store in format sector (up to 4000 characters long)")
.OptionalArgument("STR").Optional().StoreResult(&TextMessage);
config.Opts->AddLongOption('e', "erasure-encode", "erasure-encode data to recover from single-sector failures")
.Optional().NoArgument().SetFlag(&IsErasureEncode);
.Optional().StoreTrue(&IsErasureEncode);

config.Opts->SetCmdLineDescr("\n\n"
"Kikimr was designed to work with large block-devices, like 4 TiB HDDs and 1 TiB SSDs\n"
Expand All @@ -167,9 +167,9 @@ class TClientCommandDiskFormat : public TClientCommand {
SafeEntropyPoolRead(&ChunkKey, sizeof(NKikimr::NPDisk::TKey));
SafeEntropyPoolRead(&LogKey, sizeof(NKikimr::NPDisk::TKey));
SafeEntropyPoolRead(&SysLogKey, sizeof(NKikimr::NPDisk::TKey));
bool hasMainOption = config.ParseResult->FindLongOptParseResult("main-key");
bool hasMasterOption = config.ParseResult->FindLongOptParseResult("master-key");
bool hasKOption = config.ParseResult->FindCharOptParseResult('k');
bool hasMainOption = config.ParseResult->Has("main-key");
bool hasMasterOption = config.ParseResult->Has("master-key");
bool hasKOption = config.ParseResult->Has('k');
if (!hasMainOption && !hasMasterOption && !hasKOption)
ythrow yexception() << "missing main-key param";

Expand Down
6 changes: 3 additions & 3 deletions ydb/core/driver_lib/cli_utils/cli_cmds_root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class TClientCommandRoot : public TClientCommandRootKikimrBase {
}

void Config(TConfig& config) override {
NLastGetopt::TOpts& opts = *config.Opts;
HideOptions(*config.Opts);
TClientCommandOptions& opts = *config.Opts;
HideOptions(config.Opts->GetOpts());
opts.AddLongOption('k', "token", "security token").RequiredArgument("TOKEN").StoreResult(&Token);
opts.AddLongOption('s', "server", "server address to connect")
.RequiredArgument("HOST[:PORT]").StoreResult(&Address);
Expand Down Expand Up @@ -83,7 +83,7 @@ TString NewClientCommandsDescription(const TString& name, std::shared_ptr<TModul
NColorizer::TColors colors = NColorizer::AutoColors(Cout);
stream << " [options] <subcommand>" << Endl << Endl
<< colors.BoldColor() << "Subcommands" << colors.OldColor() << ":" << Endl;
commandsRoot->RenderCommandsDescription(stream, colors);
commandsRoot->RenderCommandDescription(stream, false, colors);
return stream.Str();
}

Expand Down
8 changes: 4 additions & 4 deletions ydb/core/driver_lib/cli_utils/cli_cmds_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ void TClientCommandServer::Config(TConfig& config) {
TClientCommand::Config(config);

NConfig::AddProtoConfigOptions(DepsRecorder->GetDeps().ProtoConfigFileProvider);
InitCfg.RegisterCliOptions(*config.Opts);
ProtoConfigFileProvider->RegisterCliOptions(*config.Opts);
InitCfg.RegisterCliOptions(config.Opts->GetOpts());
ProtoConfigFileProvider->RegisterCliOptions(config.Opts->GetOpts());
config.SetFreeArgsMin(0);

config.Opts->AddHelpOption('h');
config.Opts->GetOpts().AddHelpOption('h');
}

void TClientCommandServer::Parse(TConfig& config) {
TClientCommand::Parse(config);
InitCfg.ValidateOptions(*config.Opts, *config.ParseResult);
InitCfg.ValidateOptions(config.Opts->GetOpts(), config.ParseResult->GetCommandLineParseResult());
InitCfg.Parse(config.ParseResult->GetFreeArgs(), Factories->ConfigSwissKnife.get());
}

Expand Down
Loading
Loading