@@ -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+
163198void 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);
0 commit comments