/** * {@inheritdoc} */ public function execute(InputInterface $input, OutputInterface $output) { $helper = new ConfigHelper(); $configsets = $helper->getAllConfigSets(); // Were we passed a configset name? $selected = $input->getArgument('configset'); if (empty($selected)) { // If no argument passed, prompt the user for which config set to display $qhelper = $this->getHelper('question'); $message = "<question>Choose the number corresponding to which configuration set to load:</question> "; $options = array_keys($configsets); $question = new ChoiceQuestion($message, $options, 0); $selected = $qhelper->ask($input, $output, $question); // TODO: Validate argument is a valid config set } if (empty($configsets[$selected])) { $output->writeln("<error>Unable to load configset. The specified configset does not exist."); return; } $output->writeln("You chose configset: " . $configsets[$selected]); $qhelper = $this->getHelper('question'); $output->writeln("<info>This will wipe out your current DrupalCI defaults and replace them with the values from the <option=bold>{$selected}</option=bold> configset.</info>"); $message = "<question>Are you sure you wish to continue? (y/n)</question> "; $question = new ConfirmationQuestion($message, false); if (!$qhelper->ask($input, $output, $question)) { $output->writeln("<comment>Action cancelled.</comment>"); return; } $helper->activateConfig($selected); }
/** * {@inheritdoc} */ public function execute(InputInterface $input, OutputInterface $output) { $output->writeln("<info>Executing init:config</info>"); # Check whether ~/.drupalci directory exists, and force option not called # TODO: Parameterize the drupalci directory $homedir = getenv('HOME'); if (file_exists($homedir . "/.drupalci") && !$input->getOption('force')) { # Output 'configuration directory already exists, use --force to reset the DrupalCI environment' message. $output->writeln('<error>WARNING: The ~/.drupalci configuration directory already exists.</error>'); $output->writeln('<comment>Use the --force option to reset your DrupalCI environment back to default.</comment>'); $output->writeln('<comment>Note that this will wipe out all files in your ~/.drupalci directory, including existing configuration sets.</comment>'); return; } else { if ($input->getOption('force')) { $helper = $this->getHelper('question'); $output->writeln("<info>This will wipe out all files in your ~/.drupalci directory, including existing configuration sets.</info>"); $message = "<question>Are you sure you wish to continue with this action? (y/n)</question> "; $question = new ConfirmationQuestion($message, false); if (!$helper->ask($input, $output, $question)) { return; } // Forcing re-initialization of the DrupalCI environment. // Delete existing directory. $finder = new Finder(); $iterator = $finder->files()->in($homedir . '/.drupalci'); foreach ($iterator as $file) { unlink($file); } } // We now have a clean environment. // Create directories $configsdir = $homedir . "/.drupalci/configs"; $configlink = $homedir . "/.drupalci/config"; if (!file_exists($configsdir)) { mkdir($configsdir, 0777, true); $output->writeln("<info>Created {$configsdir} directory.</info>"); } else { $output->writeln("<info>Re-using existing {$configsdir} directory.</info>"); } // Copy default files over to the configs directory // TODO: Currently using placeholder files. Populate file contents. $finder = new Finder(); $directory = "./configsets"; // TODO: This means we can only execute the command from the drupalci // directory. Need to be able to run from anywhere - determine how to // get the current script execution directory (not the /bin symlink!) // and construct an absolute directory path above. $iterator = $finder->files()->in($directory); foreach ($iterator as $file) { copy($file->getRealPath(), $configsdir . "/" . $file->getFileName()); } $output->writeln("<info>Created default configuration sets.</info>"); $helper = new ConfigHelper(); // Copy a default setting file over to the current config $helper->activateConfig('d8_core_full_php5.5_mysql'); $output->writeln("<info>Created initial config set at </info><comment>{$configlink}</comment>"); } }