Skip to content

Commit e510321

Browse files
committed
Revert removing executable options (#15676)
1 parent 26f8e58 commit e510321

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
@@ -160,6 +160,41 @@ TClientCommand::TOptsParseOneLevelResult::TOptsParseOneLevelResult(TConfig& conf
160160
Init(config.Opts, _argc, const_cast<const char**>(config.ArgV));
161161
}
162162

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

224226
void CheckParamsCount() {
225227
size_t count = GetParamsCount();
226-
if (HasHelpCommand()) {
228+
if (HasHelpCommand() || HasExecutableOptions) {
227229
return;
228230
}
229231
bool minSet = ArgsSettings.Min.GetIsSet();
@@ -405,6 +407,7 @@ class TClientCommand {
405407
private:
406408
void HideOption(const TString& name);
407409
void ChangeOptionDescription(const TString& name, const TString& description);
410+
void CheckForExecutableOptions(TConfig& config);
408411

409412
constexpr static int DESCRIPTION_ALIGNMENT = 28;
410413
};

0 commit comments

Comments
 (0)