@@ -145,6 +145,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
145145 } elseif ($ input ->getOption ('tags ' )) {
146146 $ options = ['group_by ' => 'tags ' ];
147147 } elseif ($ tag = $ input ->getOption ('tag ' )) {
148+ $ tag = $ this ->findProperTagName ($ input , $ errorIo , $ object , $ tag );
148149 $ options = ['tag ' => $ tag ];
149150 } elseif ($ name = $ input ->getArgument ('name ' )) {
150151 $ name = $ this ->findProperServiceName ($ input , $ errorIo , $ object , $ name , $ input ->getOption ('show-hidden ' ));
@@ -287,6 +288,24 @@ private function findProperServiceName(InputInterface $input, SymfonyStyle $io,
287288 return $ io ->choice ('Select one of the following services to display its information ' , $ matchingServices );
288289 }
289290
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+
290309 private function findServiceIdsContaining (ContainerBuilder $ builder , string $ name , bool $ showHidden ): array
291310 {
292311 $ serviceIds = $ builder ->getServiceIds ();
@@ -306,6 +325,19 @@ private function findServiceIdsContaining(ContainerBuilder $builder, string $nam
306325 return $ foundServiceIds ?: $ foundServiceIdsIgnoringBackslashes ;
307326 }
308327
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+
309341 /**
310342 * @internal
311343 */
0 commit comments