diff --git a/config/mappings.yml b/config/mappings.yml new file mode 100644 index 0000000..b297dda --- /dev/null +++ b/config/mappings.yml @@ -0,0 +1,30 @@ +commands: + mappings: + breakpoints:debug: debug:breakpoints + cache:context:debug: debug:cache:context + chain:debug: debug:chain + config:debug: debug:config + config:settings:debug: debug:config:settings + config:validate:debug: debug:config:validate + container:debug: debug:container + cron:debug: debug:cron + database:log:debug: debug:database:log + database:table:debug: debug:database:table + entity:debug: debug:entity + event:debug: debug:event + image:styles:debug: debug:image:styles + libraries:debug: debug:libraries + module:debug: debug:module + multisite:debug: debug:multisite + permission:debug: debug:permission + plugin:debug: debug:plugin + queue:debug: debug:queue + router:debug: debug:router + settings:debug: debug:settings + site:debug: debug:site + state:debug: debug:state + theme:debug: debug:theme + update:debug: debug:update + user:debug: debug:user + views:debug: debug:views + views:plugins:debug: debug:views:plugins diff --git a/src/Application.php b/src/Application.php index 1d40ba9..49a2b50 100644 --- a/src/Application.php +++ b/src/Application.php @@ -85,9 +85,9 @@ public function trans($key) /** * {@inheritdoc} */ - public function doRun(InputInterface $input, OutputInterface $output) - { + public function doRun(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); + $messages = []; if ($commandName = $this->getCommandName($input)) { $this->commandName = $commandName; } @@ -103,14 +103,31 @@ public function doRun(InputInterface $input, OutputInterface $output) ->get('console.configuration_manager'); if ($commandName && !$this->has($commandName)) { - $io->error( - sprintf( - $this->trans('application.errors.invalid-command'), - $this->commandName - ) - ); + $config = $configurationManager->getConfiguration(); + $mappings = $config + ->get('application.commands.mappings'); + + if (array_key_exists($commandName, $mappings)) { + $commandNameMap = $mappings[$commandName]; + $messages['warning'][] = sprintf( + $this->trans('application.errors.renamed-command'), + $commandName, + $commandNameMap + ); + $this->add( + $this->find($commandNameMap)->setAliases([$commandName]) + ); + } + else { + $io->error( + sprintf( + $this->trans('application.errors.invalid-command'), + $this->commandName + ) + ); - return 1; + return 1; + } } $code = parent::doRun( @@ -118,20 +135,33 @@ public function doRun(InputInterface $input, OutputInterface $output) $output ); - if ($this->commandName != 'init' && $configurationManager->getMissingConfigurationFiles()) { - $io->warning($this->trans('application.site.errors.missing-config-file')); + if ($this->commandName != 'init' && $configurationManager->getMissingConfigurationFiles( + ) + ) { + $io->warning( + $this->trans('application.site.errors.missing-config-file') + ); $io->listing($configurationManager->getMissingConfigurationFiles()); $io->commentBlock( - $this->trans('application.site.errors.missing-config-file-command') + $this->trans( + 'application.site.errors.missing-config-file-command' + ) ); } - if ($this->getCommandName($input) == 'list' && $this->container->hasParameter('console.warning')) { + if ($this->getCommandName( + $input + ) == 'list' && $this->container->hasParameter('console.warning') + ) { $io->warning( $this->trans($this->container->getParameter('console.warning')) ); } + foreach ($messages as $type => $message) { + $io->$type($message); + } + return $code; } diff --git a/src/Utils/ConfigurationManager.php b/src/Utils/ConfigurationManager.php index b1d22ca..7f94059 100644 --- a/src/Utils/ConfigurationManager.php +++ b/src/Utils/ConfigurationManager.php @@ -94,6 +94,7 @@ public function loadConfiguration($applicationDirectory) $builder = new YamlFileConfigurationBuilder($configurationFiles); $this->configuration = $builder->build(); $this->appendCommandAliases(); + $this->appendCommandMappings(); if ($configurationFiles) { $this->missingConfigurationFiles = []; @@ -245,7 +246,27 @@ public function getConfigurationDirectories() } /** - * @return string + * @return void + */ + public function appendCommandMappings() + { + $mappings = []; + $mappingsFile = $this->applicationDirectory.DRUPAL_CONSOLE_CORE.'config/mappings.yml'; + + if (file_exists($mappingsFile)) { + $mappings = Yaml::parse(file_get_contents($mappingsFile)); + } + + if (array_key_exists('commands', $mappings) && array_key_exists('mappings', $mappings['commands'])) { + $this->configuration->set( + 'application.commands.mappings', + $mappings['commands']['mappings'] + ); + } + } + + /** + * @return void */ public function appendCommandAliases() {