@@ -164,7 +164,10 @@ class CommandLineParser {
164
164
// This collects the different subcommands that have been registered.
165
165
SmallPtrSet<SubCommand *, 4 > RegisteredSubCommands;
166
166
167
- CommandLineParser () { registerSubCommand (&SubCommand::getTopLevel ()); }
167
+ CommandLineParser () {
168
+ registerSubCommand (&SubCommand::getTopLevel ());
169
+ registerSubCommand (&SubCommand::getAll ());
170
+ }
168
171
169
172
void ResetAllOptionOccurrences ();
170
173
@@ -345,15 +348,15 @@ class CommandLineParser {
345
348
346
349
// For all options that have been registered for all subcommands, add the
347
350
// option to this subcommand now.
348
- assert (sub != &SubCommand::getAll () &&
349
- " SubCommand::getAll() should not be registered " );
350
- for ( auto &E : SubCommand::getAll (). OptionsMap ) {
351
- Option *O = E. second ;
352
- if ((O-> isPositional () || O-> isSink () || O->isConsumeAfter ()) ||
353
- O-> hasArgStr ())
354
- addOption (O, sub);
355
- else
356
- addLiteralOption (*O, sub, E. first ());
351
+ if (sub != &SubCommand::getAll ()) {
352
+ for ( auto &E : SubCommand::getAll (). OptionsMap ) {
353
+ Option *O = E. second ;
354
+ if ((O-> isPositional () || O-> isSink () || O-> isConsumeAfter ()) ||
355
+ O->hasArgStr ())
356
+ addOption (O, sub);
357
+ else
358
+ addLiteralOption (*O, sub, E. first ());
359
+ }
357
360
}
358
361
}
359
362
@@ -381,6 +384,7 @@ class CommandLineParser {
381
384
SubCommand::getTopLevel ().reset ();
382
385
SubCommand::getAll ().reset ();
383
386
registerSubCommand (&SubCommand::getTopLevel ());
387
+ registerSubCommand (&SubCommand::getAll ());
384
388
385
389
DefaultOptions.clear ();
386
390
}
@@ -528,8 +532,8 @@ SubCommand *CommandLineParser::LookupSubCommand(StringRef Name,
528
532
// Find a subcommand with the edit distance == 1.
529
533
SubCommand *NearestMatch = nullptr ;
530
534
for (auto *S : RegisteredSubCommands) {
531
- assert (S != &SubCommand::getAll () &&
532
- " SubCommand::getAll() is not expected in RegisteredSubCommands " ) ;
535
+ if (S == &SubCommand::getAll ())
536
+ continue ;
533
537
if (S->getName ().empty ())
534
538
continue ;
535
539
0 commit comments