Skip to content

Commit 8b86cdb

Browse files
authored
Merge refactoring short options (#18741)
2 parents cea6a08 + e510321 commit 8b86cdb

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,24 @@ TClientCommand::TOptsParseOneLevelResult::TOptsParseOneLevelResult(TConfig& conf
133133
optName = optName.substr(0, eqPos);
134134
if (optName.StartsWith("--")) {
135135
opt = config.Opts->FindLongOption(optName.substr(2));
136-
} else {
137-
opt = config.Opts->FindCharOption(optName[1]);
138-
}
139-
if (opt != nullptr && opt->GetHasArg() != NLastGetopt::NO_ARGUMENT) {
140-
if (eqPos == TStringBuf::npos) {
136+
if (opt != nullptr && opt->GetHasArg() != NLastGetopt::NO_ARGUMENT && eqPos == TStringBuf::npos) {
141137
++_argc;
142138
}
139+
} else {
140+
if (optName.length() > 2) {
141+
// Char option list
142+
if (eqPos != TStringBuf::npos) {
143+
throw yexception() << "Char option list " << optName << " can not be followed by \"=\" sign";
144+
}
145+
} else if (optName.length() == 2) {
146+
// Single char option
147+
opt = config.Opts->FindCharOption(optName[1]);
148+
if (opt != nullptr && opt->GetHasArg() != NLastGetopt::NO_ARGUMENT && eqPos == TStringBuf::npos) {
149+
++_argc;
150+
}
151+
} else {
152+
throw yexception() << "Wrong CLI argument \"" << optName << "\"";
153+
}
143154
}
144155
} else {
145156
--levels;
@@ -160,7 +171,17 @@ void TClientCommand::CheckForExecutableOptions(TConfig& config) {
160171
if (optName.StartsWith("--")) {
161172
opt = config.Opts->FindLongOption(optName.substr(2));
162173
} else {
163-
opt = config.Opts->FindCharOption(optName[1]);
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+
}
164185
}
165186
if (config.ExecutableOptions.find(optName) != config.ExecutableOptions.end()) {
166187
config.HasExecutableOptions = true;

0 commit comments

Comments
 (0)