Skip to content

Commit a659db8

Browse files
committed
TClientCommandOptions
1 parent 7402c4e commit a659db8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1734
-1148
lines changed

ydb/apps/ydb/commands/ydb_root.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ void TClientCommandRoot::SetCredentialsGetter(TConfig& config) {
4545
if (config.UseMetadataCredentials) {
4646
return CreateIamCredentialsProviderFactory();
4747
}
48+
if (config.SaKeyParams) {
49+
return CreateIamJwtParamsCredentialsProviderFactory(
50+
{ {.Endpoint = config.IamEndpoint}, config.SaKeyParams });
51+
}
4852
if (config.SaKeyFile) {
4953
return CreateIamJwtFileCredentialsProviderFactory(
5054
{ {.Endpoint = config.IamEndpoint}, config.SaKeyFile });
@@ -77,8 +81,7 @@ namespace {
7781
void TYdbClientCommandRoot::Config(TConfig& config) {
7882
TClientCommandRoot::Config(config);
7983

80-
NLastGetopt::TOpts& opts = *config.Opts;
81-
RemoveOption(opts, "svnrevision");
84+
RemoveOption(config.Opts->GetOpts(), "svnrevision");
8285
}
8386

8487
int TYdbClientCommandRoot::Run(TConfig& config) {

ydb/apps/ydb/ut/parse_command_line.cpp

+20-23
Original file line numberDiff line numberDiff line change
@@ -525,17 +525,16 @@ Y_UNIT_TEST_SUITE(ParseOptionsTest) {
525525
{"YDB_PASSWORD", "pwd"},
526526
});
527527

528-
// TODO: make these options mutually exclusive
529-
// ExpectFail();
530-
// RunCli({
531-
// "-v",
532-
// "-e", GetEndpoint(),
533-
// "-d", GetDatabase(),
534-
// "--user", "test-user",
535-
// "--no-password",
536-
// "--password-file", passwordFile,
537-
// "scheme", "ls",
538-
// });
528+
ExpectFail();
529+
RunCli({
530+
"-v",
531+
"-e", GetEndpoint(),
532+
"-d", GetDatabase(),
533+
"--user", "test-user",
534+
"--no-password",
535+
"--password-file", passwordFile,
536+
"scheme", "ls",
537+
});
539538

540539
TString profile = fmt::format(R"yaml(
541540
profiles:
@@ -636,18 +635,16 @@ Y_UNIT_TEST_SUITE(ParseOptionsTest) {
636635
{},
637636
profile);
638637

639-
// TODO: validate that there is no ambiguity in setting passwords
640-
// ExpectFail();
641-
// RunCli({
642-
// "-v",
643-
// "-p", "test_profile_with_both_passwords",
644-
// "scheme", "ls",
645-
// },
646-
// {},
647-
// profile);
648-
649-
// TODO: Fix this case
650-
//ExpectUserAndPassword("user_no_password", "", "no-password-token");
638+
ExpectFail();
639+
RunCli({
640+
"-v",
641+
"-p", "test_profile_with_both_passwords",
642+
"scheme", "ls",
643+
},
644+
{},
645+
profile);
646+
647+
ExpectUserAndPassword("user_no_password", "", "no-password-token");
651648
RunCli({
652649
"-v",
653650
"-p", "test_profile_without_password",

ydb/core/driver_lib/cli_base/cli_cmds_db.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class TClientCommandSchemaExec : public TClientCommandBase {
131131
virtual void Config(TConfig& config) override {
132132
TClientCommand::Config(config);
133133
ReturnTxId = false;
134-
config.Opts->AddLongOption('t', "txid", "Print TxId").NoArgument().SetFlag(&ReturnTxId);
134+
config.Opts->AddLongOption('t', "txid", "Print TxId").StoreTrue(&ReturnTxId);
135135
config.SetFreeArgsNum(1);
136136
SetFreeArgTitle(0, "<SCHEMA-PROTO>", "Schema protobuf or file with schema protobuf");
137137
}
@@ -205,14 +205,14 @@ class TClientCommandSchemaDescribe : public TClientCommand {
205205
Boundaries = false;
206206
config.SetFreeArgsNum(1);
207207
SetFreeArgTitle(0, "<PATH>", "Schema path or pathId (e.g. 72075186232623600/1225)");
208-
config.Opts->AddLongOption('t', "tree", "Show schema path tree").NoArgument().SetFlag(&Tree);
209-
config.Opts->AddLongOption('d', "details", "Show detailed information (like columns in a table)").NoArgument().SetFlag(&Details);
210-
config.Opts->AddLongOption('a', "acl", "Show owner and acl information").NoArgument().SetFlag(&AccessRights);
211-
config.Opts->AddLongOption('e', "effacl", "Show effective acl information").NoArgument().SetFlag(&AccessRightsEffective);
212-
config.Opts->AddLongOption('b', "backup", "Show backup information").NoArgument().SetFlag(&BackupInfo);
213-
config.Opts->AddLongOption('P', "protobuf", "Debug print all info as is").NoArgument().SetFlag(&Protobuf);
214-
config.Opts->AddLongOption('s', "stats", "Return partition stats").NoArgument().SetFlag(&PartitionStats);
215-
config.Opts->AddLongOption("boundaries", "Return boundaries").NoArgument().SetFlag(&Boundaries);
208+
config.Opts->AddLongOption('t', "tree", "Show schema path tree").StoreTrue(&Tree);
209+
config.Opts->AddLongOption('d', "details", "Show detailed information (like columns in a table)").StoreTrue(&Details);
210+
config.Opts->AddLongOption('a', "acl", "Show owner and acl information").StoreTrue(&AccessRights);
211+
config.Opts->AddLongOption('e', "effacl", "Show effective acl information").StoreTrue(&AccessRightsEffective);
212+
config.Opts->AddLongOption('b', "backup", "Show backup information").StoreTrue(&BackupInfo);
213+
config.Opts->AddLongOption('P', "protobuf", "Debug print all info as is").StoreTrue(&Protobuf);
214+
config.Opts->AddLongOption('s', "stats", "Return partition stats").StoreTrue(&PartitionStats);
215+
config.Opts->AddLongOption("boundaries", "Return boundaries").StoreTrue(&Boundaries);
216216
}
217217

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

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

13241324
virtual void Parse(TConfig& config) override {

ydb/core/driver_lib/cli_base/cli_cmds_root.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ TClientCommandRootKikimrBase::TClientCommandRootKikimrBase(const TString& name)
1818

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

2424
TStringBuilder tokenHelp;

ydb/core/driver_lib/cli_utils/cli_cmds_cms.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class TClientCommandManageRequest : public TCmsClientCommand
207207
} else {
208208
config.SetFreeArgsNum(0);
209209
}
210-
config.Opts->AddLongOption("dry", "Dry run").NoArgument().SetFlag(&DryRun);
210+
config.Opts->AddLongOption("dry", "Dry run").StoreTrue(&DryRun);
211211
}
212212

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

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

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

441441
config.Opts->AddLongOption("user", "User name").Required()
442442
.RequiredArgument("NAME").StoreResult(&User);
443-
config.Opts->AddLongOption("dry", "Dry run").NoArgument().SetFlag(&DryRun);
443+
config.Opts->AddLongOption("dry", "Dry run").StoreTrue(&DryRun);
444444
config.Opts->AddLongOption("reason", "Informational request description")
445445
.RequiredArgument("STRING").StoreResult(&Reason);
446446
config.Opts->AddLongOption("schedule", "Schedule action in CMS if it's disallowed right now")
447-
.NoArgument().SetFlag(&Schedule);
447+
.StoreTrue(&Schedule);
448448
config.Opts->AddLongOption("hours", "Permission duration")
449449
.RequiredArgument("NUM").StoreResult(&Hours);
450450
config.Opts->AddLongOption("minutes", "Permission duration")
451451
.RequiredArgument("NUM").StoreResult(&Minutes);
452452
config.Opts->AddLongOption("tenant-policy", "Policy for computation node restart")
453453
.RequiredArgument("none|default").StoreResult(&TenantPolicy);
454454
config.Opts->AddLongOption("allow-partial", "Allow partial permission")
455-
.NoArgument().SetFlag(&AllowPartial);
455+
.StoreTrue(&AllowPartial);
456456
config.Opts->AddLongOption("availability-mode", "Availability mode")
457457
.RequiredArgument("max|keep|force").DefaultValue("max").StoreResult(&AvailabilityMode);
458458
config.Opts->AddLongOption("evict-vdisks", "Evict vdisks before granting permission(s)")
459-
.NoArgument().SetFlag(&EvictVDisks);
459+
.StoreTrue(&EvictVDisks);
460460
config.Opts->AddLongOption("priority", "Request priority")
461461
.RequiredArgument("NUM").StoreResult(&Priority);
462-
462+
463463
}
464464

465465
void Parse(TConfig& config) override
@@ -718,7 +718,7 @@ class TClientCommandManageNotification : public TCmsClientCommand
718718
} else {
719719
config.SetFreeArgsNum(0);
720720
}
721-
config.Opts->AddLongOption("dry", "Dry run").NoArgument().SetFlag(&DryRun);
721+
config.Opts->AddLongOption("dry", "Dry run").StoreTrue(&DryRun);
722722
}
723723

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

852852
void Parse(TConfig& config) override

ydb/core/driver_lib/cli_utils/cli_cmds_config.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ class TInit : public TClientCommand {
9595

9696
config.Opts->AddLongOption('n', "dry-run", "do not apply updates")
9797
.Optional()
98-
.NoArgument()
99-
.SetFlag(&DryRun);
98+
.StoreTrue(&DryRun);
10099
}
101100

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

181180
config.Opts->AddLongOption('n', "dry-run", "do not apply updates")
182181
.Optional()
183-
.NoArgument()
184-
.SetFlag(&DryRun);
182+
.StoreTrue(&DryRun);
185183
}
186184

187185
int Run(TConfig& config) override {

ydb/core/driver_lib/cli_utils/cli_cmds_console.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class TClientCommandConsoleConfigsUpdate : public TConsoleClientCommand {
195195
virtual void Config(TConfig& config) override {
196196
TConsoleClientCommand::Config(config);
197197
config.Opts->AddLongOption("dry-run", "Execute configure request in dry-run mode")
198-
.NoArgument().SetFlag(&DryRun);
198+
.StoreTrue(&DryRun);
199199
config.Opts->AddLongOption("out-dir", "Output affected configs into specified directory")
200200
.RequiredArgument("PATH").StoreResult(&OutDir);
201201
config.SetFreeArgsNum(1);
@@ -525,10 +525,10 @@ class TClientCommandConsoleConfigSet : public TConsoleClientCommand {
525525
virtual void Config(TConfig& config) override {
526526
TConsoleClientCommand::Config(config);
527527
config.Opts->AddLongOption("merge", "Merge provided config with the current one")
528-
.NoArgument().SetFlag(&Merge);
528+
.StoreTrue(&Merge);
529529
config.Opts->AddLongOption("merge-overwrite-repeated", "Merge provided config with the current one"
530530
" but overwrite those repeated field which are not empty in provided config")
531-
.NoArgument().SetFlag(&MergeOverwriteRepeated);
531+
.StoreTrue(&MergeOverwriteRepeated);
532532
config.SetFreeArgsNum(1);
533533
SetFreeArgTitle(0, "<CONFIG-PROTO>", "Console config protobuf or file with protobuf");
534534
}

ydb/core/driver_lib/cli_utils/cli_cmds_disk.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ class TClientCommandDiskInfo : public TClientCommand {
2929
.Optional().AppendTo(&MainKeyTmp); // TODO: make required
3030
config.Opts->AddLongOption("master-key", "obsolete: use main-key").RequiredArgument("NUM")
3131
.Optional().AppendTo(&MainKeyTmp); // TODO: remove after migration
32-
config.Opts->AddLongOption('v', "verbose", "output detailed information for debugging").Optional().NoArgument()
33-
.SetFlag(&IsVerbose);
34-
config.Opts->AddLongOption('l', "lock", "lock device before reading disk info").Optional().NoArgument()
35-
.SetFlag(&LockDevice);
32+
config.Opts->AddLongOption('v', "verbose", "output detailed information for debugging").Optional()
33+
.StoreTrue(&IsVerbose);
34+
config.Opts->AddLongOption('l', "lock", "lock device before reading disk info").Optional()
35+
.StoreTrue(&LockDevice);
3636
}
3737

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

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

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

ydb/core/driver_lib/cli_utils/cli_cmds_root.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class TClientCommandRoot : public TClientCommandRootKikimrBase {
3131
}
3232

3333
void Config(TConfig& config) override {
34-
NLastGetopt::TOpts& opts = *config.Opts;
35-
HideOptions(*config.Opts);
34+
TClientCommandOptions& opts = *config.Opts;
35+
HideOptions(config.Opts->GetOpts());
3636
opts.AddLongOption('k', "token", "security token").RequiredArgument("TOKEN").StoreResult(&Token);
3737
opts.AddLongOption('s', "server", "server address to connect")
3838
.RequiredArgument("HOST[:PORT]").StoreResult(&Address);

ydb/core/driver_lib/cli_utils/cli_cmds_server.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ void TClientCommandServer::Config(TConfig& config) {
5555
TClientCommand::Config(config);
5656

5757
NConfig::AddProtoConfigOptions(DepsRecorder->GetDeps().ProtoConfigFileProvider);
58-
InitCfg.RegisterCliOptions(*config.Opts);
59-
ProtoConfigFileProvider->RegisterCliOptions(*config.Opts);
58+
InitCfg.RegisterCliOptions(config.Opts->GetOpts());
59+
ProtoConfigFileProvider->RegisterCliOptions(config.Opts->GetOpts());
6060
config.SetFreeArgsMin(0);
6161

62-
config.Opts->AddHelpOption('h');
62+
config.Opts->GetOpts().AddHelpOption('h');
6363
}
6464

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

0 commit comments

Comments
 (0)