Skip to content

Commit 36d1878

Browse files
authored
Revert removing executable options (#15676)
1 parent 3f02aa6 commit 36d1878

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

ydb/public/lib/ydb_cli/common/command.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,41 @@ TClientCommand::TOptsParseOneLevelResult::TOptsParseOneLevelResult(TConfig& conf
159159
Init(config.Opts, _argc, const_cast<const char**>(config.ArgV));
160160
}
161161

162+
void TClientCommand::CheckForExecutableOptions(TConfig& config) {
163+
int argc = 1;
164+
165+
while (argc < config.ArgC && config.ArgV[argc][0] == '-') {
166+
const NLastGetopt::TOpt* opt = nullptr;
167+
TStringBuf optName(config.ArgV[argc]);
168+
auto eqPos = optName.find('=');
169+
optName = optName.substr(0, eqPos);
170+
if (optName.StartsWith("--")) {
171+
opt = config.Opts->FindLongOption(optName.substr(2));
172+
} else {
173+
if (optName.length() > 2) {
174+
// Char option list
175+
if (eqPos != TStringBuf::npos) {
176+
throw yexception() << "Char option list " << optName << " can not be followed by \"=\" sign";
177+
}
178+
} else if (optName.length() == 2) {
179+
// Single char option
180+
opt = config.Opts->FindCharOption(optName[1]);
181+
} else {
182+
throw yexception() << "Wrong CLI argument \"" << optName << "\"";
183+
}
184+
}
185+
if (config.ExecutableOptions.find(optName) != config.ExecutableOptions.end()) {
186+
config.HasExecutableOptions = true;
187+
}
188+
if (opt != nullptr && opt->GetHasArg() != NLastGetopt::NO_ARGUMENT) {
189+
if (eqPos == TStringBuf::npos) {
190+
++argc;
191+
}
192+
}
193+
++argc;
194+
}
195+
}
196+
162197
void TClientCommand::Config(TConfig& config) {
163198
config.Opts = &Opts;
164199
config.OnlyExplicitProfile = OnlyExplicitProfile;
@@ -197,6 +232,7 @@ void TClientCommand::Prepare(TConfig& config) {
197232
config.ArgsSettings = TConfig::TArgSettings();
198233
config.Opts = &Opts;
199234
Config(config);
235+
CheckForExecutableOptions(config);
200236
config.CheckParamsCount();
201237
SetCustomUsage(config);
202238
SaveParseResult(config);

ydb/public/lib/ydb_cli/common/command.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ class TClientCommand {
102102
TVector<TString> Tokens;
103103
TString SecurityToken;
104104
TList<TCommandInfo> ParentCommands;
105+
THashSet<TString> ExecutableOptions;
106+
bool HasExecutableOptions = false;
105107
TString Path;
106108
TArgSettings ArgsSettings;
107109
TString Address;
@@ -221,7 +223,7 @@ class TClientCommand {
221223

222224
void CheckParamsCount() {
223225
size_t count = GetParamsCount();
224-
if (HasHelpCommand()) {
226+
if (HasHelpCommand() || HasExecutableOptions) {
225227
return;
226228
}
227229
bool minSet = ArgsSettings.Min.GetIsSet();
@@ -380,6 +382,7 @@ class TClientCommand {
380382
private:
381383
void HideOption(const TString& name);
382384
void ChangeOptionDescription(const TString& name, const TString& description);
385+
void CheckForExecutableOptions(TConfig& config);
383386

384387
constexpr static int DESCRIPTION_ALIGNMENT = 28;
385388
};

0 commit comments

Comments
 (0)