@@ -145,6 +145,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
145
145
} elseif ($ input ->getOption ('tags ' )) {
146
146
$ options = ['group_by ' => 'tags ' ];
147
147
} elseif ($ tag = $ input ->getOption ('tag ' )) {
148
+ $ tag = $ this ->findProperTagName ($ input , $ errorIo , $ object , $ tag );
148
149
$ options = ['tag ' => $ tag ];
149
150
} elseif ($ name = $ input ->getArgument ('name ' )) {
150
151
$ name = $ this ->findProperServiceName ($ input , $ errorIo , $ object , $ name , $ input ->getOption ('show-hidden ' ));
@@ -287,6 +288,24 @@ private function findProperServiceName(InputInterface $input, SymfonyStyle $io,
287
288
return $ io ->choice ('Select one of the following services to display its information ' , $ matchingServices );
288
289
}
289
290
291
+ private function findProperTagName (InputInterface $ input , SymfonyStyle $ io , ContainerBuilder $ builder , string $ tagName ): string
292
+ {
293
+ if (\in_array ($ tagName , $ builder ->findTags (), true ) || !$ input ->isInteractive ()) {
294
+ return $ tagName ;
295
+ }
296
+
297
+ $ matchingTags = $ this ->findTagsContaining ($ builder , $ tagName );
298
+ if (!$ matchingTags ) {
299
+ throw new InvalidArgumentException (sprintf ('No tags found that match "%s". ' , $ tagName ));
300
+ }
301
+
302
+ if (1 === \count ($ matchingTags )) {
303
+ return $ matchingTags [0 ];
304
+ }
305
+
306
+ return $ io ->choice ('Select one of the following tags to display its information ' , $ matchingTags );
307
+ }
308
+
290
309
private function findServiceIdsContaining (ContainerBuilder $ builder , string $ name , bool $ showHidden ): array
291
310
{
292
311
$ serviceIds = $ builder ->getServiceIds ();
@@ -306,6 +325,19 @@ private function findServiceIdsContaining(ContainerBuilder $builder, string $nam
306
325
return $ foundServiceIds ?: $ foundServiceIdsIgnoringBackslashes ;
307
326
}
308
327
328
+ private function findTagsContaining (ContainerBuilder $ builder , string $ tagName ): array
329
+ {
330
+ $ tags = $ builder ->findTags ();
331
+ $ foundTags = [];
332
+ foreach ($ tags as $ tag ) {
333
+ if (str_contains ($ tag , $ tagName )) {
334
+ $ foundTags [] = $ tag ;
335
+ }
336
+ }
337
+
338
+ return $ foundTags ;
339
+ }
340
+
309
341
/**
310
342
* @internal
311
343
*/
0 commit comments