diff --git a/composer.lock b/composer.lock index e46d32e..a8b5239 100644 --- a/composer.lock +++ b/composer.lock @@ -175,16 +175,16 @@ }, { "name": "drupal/console-en", - "version": "1.0.0-rc7", + "version": "1.0.0-rc8", "source": { "type": "git", "url": "https://github.com/hechoendrupal/drupal-console-en.git", - "reference": "5807dce9efd84ccb1198a926eea03b600b8a93e6" + "reference": "789a088b3b6ecf77bc245d905a86387ada105245" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/hechoendrupal/drupal-console-en/zipball/5807dce9efd84ccb1198a926eea03b600b8a93e6", - "reference": "5807dce9efd84ccb1198a926eea03b600b8a93e6", + "url": "https://api.github.com/repos/hechoendrupal/drupal-console-en/zipball/789a088b3b6ecf77bc245d905a86387ada105245", + "reference": "789a088b3b6ecf77bc245d905a86387ada105245", "shasum": "" }, "type": "drupal-console-language", @@ -225,7 +225,7 @@ "drupal", "symfony" ], - "time": "2016-11-05 06:21:34" + "time": "2016-11-13 00:44:14" }, { "name": "stecman/symfony-console-completion", diff --git a/src/Bootstrap/DrupalConsoleCore.php b/src/Bootstrap/DrupalConsoleCore.php index 9a6efb1..356eeef 100644 --- a/src/Bootstrap/DrupalConsoleCore.php +++ b/src/Bootstrap/DrupalConsoleCore.php @@ -55,6 +55,13 @@ public function boot() $this->appRoot?$this->appRoot:$this->root ); + if (stripos($this->root, '/bin/') <= 0) { + $container->set( + 'console.root', + $this->root + ); + } + $container->get('console.renderer') ->setSkeletonDirs( [ diff --git a/src/Command/InitCommand.php b/src/Command/InitCommand.php index 10e37e2..96c09b9 100644 --- a/src/Command/InitCommand.php +++ b/src/Command/InitCommand.php @@ -37,6 +37,16 @@ class InitCommand extends Command */ protected $configurationManager; + /** + * @var string + */ + protected $appRoot; + + /** + * @var string + */ + protected $consoleRoot; + /** * @var InitGenerator */ @@ -50,25 +60,26 @@ class InitCommand extends Command 'generate_chain' => false ]; - private $webRootDirectories = [ - 'web', - 'docroot' - ]; - /** * InitCommand constructor. * @param ShowFile $showFile * @param ConfigurationManager $configurationManager * @param InitGenerator $generator + * @param string $appRoot + * @param string $consoleRoot */ public function __construct( ShowFile $showFile, ConfigurationManager $configurationManager, - InitGenerator $generator + InitGenerator $generator, + $appRoot, + $consoleRoot = null ) { $this->showFile = $showFile; $this->configurationManager = $configurationManager; $this->generator = $generator; + $this->appRoot = $appRoot; + $this->consoleRoot = $consoleRoot; parent::__construct(); } @@ -80,6 +91,12 @@ protected function configure() $this ->setName('init') ->setDescription($this->trans('commands.init.description')) + ->addOption( + 'destination', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.init.options.destination') + ) ->addOption( 'override', null, @@ -87,10 +104,10 @@ protected function configure() $this->trans('commands.init.options.override') ) ->addOption( - 'local', + 'autocomplete', null, InputOption::VALUE_NONE, - $this->trans('commands.init.options.local') + $this->trans('commands.init.options.autocomplete') ); } @@ -100,27 +117,26 @@ protected function configure() protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); - $local = $input->getOption('local'); + $destination = $input->getOption('destination'); + $autocomplete = $input->getOption('autocomplete'); $configuration = $this->configurationManager->getConfiguration(); - if (!$local) { - $local = $io->confirm( - $this->trans('commands.init.questions.local'), - true - ); - $input->setOption('local', $local); - } - - if ($local) { - $root = null; - foreach ($this->webRootDirectories as $webRootDirectory) { - if (!$root && is_dir(getcwd().'/'.$webRootDirectory)) { - $root = $webRootDirectory; - } + if (!$destination) { + if ($this->appRoot && $this->consoleRoot) { + $destinationList[] = $this->configurationManager + ->getConsoleDirectory(); + $destinationList[] = $this->consoleRoot . '/console/'; + $destination = $io->choice( + $this->trans('commands.init.questions.destination'), + $destinationList + ); } - $this->configParameters['root'] = $root?:$io->askEmpty( - $this->trans('commands.init.questions.root') - ); + else { + $destination = $this->configurationManager + ->getConsoleDirectory(); + } + + $input->setOption('destination', $destination); } $this->configParameters['language'] = $io->choiceNoList( @@ -147,6 +163,14 @@ protected function interact(InputInterface $input, OutputInterface $output) $this->trans('commands.init.questions.generate-chain'), false ); + + if (!$autocomplete) { + $autocomplete = $io->confirm( + $this->trans('commands.init.questions.autocomplete'), + false + ); + $input->setOption('autocomplete', $autocomplete); + } } /** @@ -156,8 +180,12 @@ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $copiedFiles = []; + $destination = $input->getOption('destination'); + $autocomplete = $input->getOption('autocomplete'); $override = $input->getOption('override'); - $local = $input->getOption('local'); + if (!$destination) { + $destination = $this->configurationManager->getConsoleDirectory(); + } $finder = new Finder(); $finder->in( @@ -170,21 +198,21 @@ protected function execute(InputInterface $input, OutputInterface $output) $finder->files(); foreach ($finder as $configFile) { - $source = sprintf( + $sourceFile = sprintf( '%s%s/config/dist/%s', $this->configurationManager->getApplicationDirectory(), DRUPAL_CONSOLE_CORE, $configFile->getRelativePathname() ); - $destination = sprintf( + $destinationFile = sprintf( '%s%s', - $this->configurationManager->getConsoleDirectory(), + $destination, $configFile->getRelativePathname() ); - if ($this->copyFile($source, $destination, $override)) { - $copiedFiles[] = $destination; + if ($this->copyFile($sourceFile, $destinationFile, $override)) { + $copiedFiles[] = $destinationFile; } } @@ -193,19 +221,22 @@ protected function execute(InputInterface $input, OutputInterface $output) $io->newLine(); } - $processBuilder = new ProcessBuilder(array('bash')); - $process = $processBuilder->getProcess(); - $process->setCommandLine('echo $_'); - $process->run(); - $fullPathExecutable = explode('/', $process->getOutput()); - $executableName = trim(end($fullPathExecutable)); - $process->stop(); + $executableName = null; + if ($autocomplete) { + $processBuilder = new ProcessBuilder(array('bash')); + $process = $processBuilder->getProcess(); + $process->setCommandLine('echo $_'); + $process->run(); + $fullPathExecutable = explode('/', $process->getOutput()); + $executableName = trim(end($fullPathExecutable)); + $process->stop(); + } $this->generator->generate( $this->configurationManager->getConsoleDirectory(), $executableName, $override, - $local, + $destination, $this->configParameters ); diff --git a/src/Generator/InitGenerator.php b/src/Generator/InitGenerator.php index ce8e534..d1b4123 100644 --- a/src/Generator/InitGenerator.php +++ b/src/Generator/InitGenerator.php @@ -16,14 +16,14 @@ class InitGenerator extends Generator * @param string $userHome * @param string $executableName * @param boolean $override - * @param boolean $local + * @param string $destination * @param array $configParameters */ public function generate( $userHome, $executableName, $override, - $local, + $destination, $configParameters ) { $configParameters = array_map( @@ -37,8 +37,8 @@ function ($item) { ); $configFile = $userHome . 'config.yml'; - if ($local) { - $configFile = getcwd().'/console/config.yml'; + if ($destination) { + $configFile = $destination.'config.yml'; } if (file_exists($configFile) && $override) { @@ -54,20 +54,22 @@ function ($item) { $configParameters ); - $parameters = [ - 'executable' => $executableName, - ]; + if ($executableName) { + $parameters = [ + 'executable' => $executableName, + ]; - $this->renderFile( - 'core/autocomplete/console.rc.twig', - $userHome.'console.rc', - $parameters - ); + $this->renderFile( + 'core/autocomplete/console.rc.twig', + $userHome . 'console.rc', + $parameters + ); - $this->renderFile( - 'core/autocomplete/console.fish.twig', - $userHome.'drupal.fish', - $parameters - ); + $this->renderFile( + 'core/autocomplete/console.fish.twig', + $userHome . 'drupal.fish', + $parameters + ); + } } } diff --git a/src/Utils/ConfigurationManager.php b/src/Utils/ConfigurationManager.php index c8eb498..0926745 100644 --- a/src/Utils/ConfigurationManager.php +++ b/src/Utils/ConfigurationManager.php @@ -58,10 +58,11 @@ public function loadConfiguration($applicationDirectory) foreach ($configurationDirectories as $configurationDirectory) { $file = $configurationDirectory . 'config.yml'; - if ( is_dir($configurationDirectory) && - stripos($configurationDirectory, '/vendor/') <= 0 && - stripos($configurationDirectory, '/bin/') <= 0 && - stripos($configurationDirectory, 'console/') > 0) {; + if (is_dir($configurationDirectory) + && stripos($configurationDirectory, '/vendor/') <= 0 + && stripos($configurationDirectory, '/bin/') <= 0 + && stripos($configurationDirectory, 'console/') > 0 + ) { $this->configurationDirectories[] = str_replace('//', '/', $configurationDirectory); } @@ -226,7 +227,7 @@ public function readDrushEquivalents($commandName) } /** - * @deprecated + * @return string */ public function getConsoleDirectory() { @@ -236,14 +237,16 @@ public function getConsoleDirectory() /** * @return array */ - public function getMissingConfigurationFiles() { + public function getMissingConfigurationFiles() + { return $this->missingConfigurationFiles; } /** * @return array */ - public function getConfigurationDirectories() { + public function getConfigurationDirectories() + { return $this->configurationDirectories; } diff --git a/templates/core/init/config.yml.twig b/templates/core/init/config.yml.twig index af90321..abcad05 100644 --- a/templates/core/init/config.yml.twig +++ b/templates/core/init/config.yml.twig @@ -45,6 +45,3 @@ application: generate-chain: {{generate_chain}} ## yes: false composer: false -{% if root is defined and root is not empty %} - root: '{{root}}' -{% endif %}