77use ACSEO \TypesenseBundle \Manager \CollectionManager ;
88use Symfony \Component \Console \Command \Command ;
99use Symfony \Component \Console \Input \InputInterface ;
10+ use Symfony \Component \Console \Input \InputOption ;
1011use Symfony \Component \Console \Output \OutputInterface ;
12+ use Symfony \Component \Console \Style \SymfonyStyle ;
1113
1214class CreateCommand extends Command
1315{
@@ -24,16 +26,33 @@ protected function configure()
2426 {
2527 $ this
2628 ->setName (self ::$ defaultName )
29+ ->addOption ('indexes ' , null , InputOption::VALUE_OPTIONAL , 'The index(es) to repopulate. Comma separated values ' )
2730 ->setDescription ('Create Typsenses indexes ' )
2831
2932 ;
3033 }
3134
3235 protected function execute (InputInterface $ input , OutputInterface $ output ): int
3336 {
34- $ defs = $ this -> collectionManager -> getCollectionDefinitions ( );
37+ $ io = new SymfonyStyle ( $ input , $ output );
3538
36- foreach ($ defs as $ name => $ def ) {
39+ $ collectionDefinitions = $ this ->collectionManager ->getCollectionDefinitions ();
40+ $ indexes = (null !== $ indexes = $ input ->getOption ('indexes ' )) ? explode (', ' , $ indexes ) : \array_keys ($ collectionDefinitions );
41+
42+ foreach ($ indexes as $ index ) {
43+ if (!isset ($ collectionDefinitions [$ index ])) {
44+ $ io ->error ('Unable to find index " ' .$ index .'" in collection definition (available : ' .implode (', ' , array_keys ($ collectionDefinitions )).') ' );
45+
46+ return 2 ;
47+ }
48+ }
49+
50+ // filter collection definitions
51+ $ collectionDefinitions = array_filter ($ collectionDefinitions , function ($ key ) use ($ indexes ) {
52+ return \in_array ($ key , $ indexes , true );
53+ }, ARRAY_FILTER_USE_KEY );
54+
55+ foreach ($ collectionDefinitions as $ name => $ def ) {
3756 $ name = $ def ['name ' ];
3857 $ typesenseName = $ def ['typesense_name ' ];
3958 try {
0 commit comments