/** * Initialize a configuration files */ public function initConfig(OutputInterface $output = null, $noInteraction = false) { $log = function ($message) use($output) { if ($output) { $output->writeln($message); } }; if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { throw new \RuntimeException('This feature is currently only supported on Linux and OSX (maybe). Please submit a PR to support it on windows.'); } $configDir = $this->getConfigDir(); $distDir = $this->getDistConfigDir(); if (!$this->filesystem->exists($configDir)) { $log('<info>[+] Creating directory:</info> ' . $configDir); $this->filesystem->mkdir($configDir); } $configFilenames = array('alias.yml', 'phpcrsh.yml'); foreach ($configFilenames as $configFilename) { $srcFile = $distDir . '/' . $configFilename; $destFile = $configDir . '/' . $configFilename; if (!$this->filesystem->exists($srcFile)) { throw new \Exception('Dist (source) file "' . $srcFile . '" does not exist.'); } if ($this->filesystem->exists($destFile)) { if (false === $noInteraction) { $confirmed = $this->questionHelper->askConfirmation($output, '"' . $configFilename . '" already exists, do you want to overwrite it?'); if (!$confirmed) { continue; } } else { $log(sprintf('<info>File</info> %s <info> already exists, not overwriting.', $destFile)); } } $this->filesystem->copy($srcFile, $destFile); $log('<info>[+] Creating file:</info> ' . $destFile); } }
/** */ private function userWantsToOverwrite() { $question = new Question("Class " . $this->className . " already exist, do you want to overwrite it?", false); return $this->dialogHelper->ask($this->inputInterface, $this->out, $question); }