@@ -160,6 +160,41 @@ TClientCommand::TOptsParseOneLevelResult::TOptsParseOneLevelResult(TConfig& conf
160
160
Init (config.Opts , _argc, const_cast <const char **>(config.ArgV ));
161
161
}
162
162
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
+
163
198
void TClientCommand::Config (TConfig& config) {
164
199
config.Opts = &Opts;
165
200
config.OnlyExplicitProfile = OnlyExplicitProfile;
@@ -198,6 +233,7 @@ void TClientCommand::Prepare(TConfig& config) {
198
233
config.ArgsSettings = TConfig::TArgSettings ();
199
234
config.Opts = &Opts;
200
235
Config (config);
236
+ CheckForExecutableOptions (config);
201
237
config.CheckParamsCount ();
202
238
SetCustomUsage (config);
203
239
SaveParseResult (config);
0 commit comments