addOption("instance", "I", InputOption::VALUE_REQUIRED, "Specify the instance name", "default"); $this->addOption("script", "s", InputOption::VALUE_NONE, "The command is a script (use 'list' for list)"); $this->addArgument("service", InputArgument::REQUIRED, "The service name"); $this->addArgument("execute", InputArgument::REQUIRED, "The command or script to execute"); $this->addArgument("arguments", InputArgument::IS_ARRAY, "Arguments"); } protected function execute(InputInterface $input, OutputInterface $output) { $serviceRegistry = $this->getServiceRegistry(); $containerManager = $this->getContainerManager(); $instanceName = $input->getOption("instance"); $serviceName = $input->getArgument("service"); $command = $input->getArgument("execute"); $serviceInfo = $serviceRegistry->findServiceByName($serviceName); if ($command == "list") { $scripts = (array)($serviceInfo['scripts']??[]); $output->writeln("Available scripts:"); foreach ($scripts as $script=>$meta) { $output->writeln(sprintf(" %s - %s", $script, $meta['info']??"?")); } return self::SUCCESS; } else { $cmdl = [ $input->getArgument("execute") ]; array_push($cmdl, ...$input->getArgument("arguments")); $containerManager->execute($serviceInfo, $instanceName, $cmdl); } return self::SUCCESS; } }