/** * {@inheritdoc} */ public function execute(InputInterface $input, OutputInterface $output) { $config_name = $input->getArgument('configset_name'); $helper = new ConfigHelper(); $configsets = $helper->getAllConfigSets(); // Ensure we have a 'current' config $current = $helper->getCurrentConfigSetParsed(); if (empty($current)) { $output->writeln("<error>Unable to save an empty configuration set.</error>"); $output->writeln("<info>Use the <option=bold>'drupalci config:set [variablename]=[value]'</option=bold> command to set some configuration defaults before attempting to save a new config set.</info>"); return; } // Check if configset name already exists if (in_array($config_name, array_keys($configsets))) { // Prompt the user that this will overwrite the existing configuration setting file $qhelper = $this->getHelper('question'); $output->writeln("<error>The <option=bold>{$config_name}</option=bold> config set already exists.</error>"); $output->writeln("<info>Continuing will overwrite the existing file with the current configuration values.</info>"); $message = "<question>Are you sure you wish to continue? (yes/no)</question> "; $question = new ConfirmationQuestion($message, false); if (!$qhelper->ask($input, $output, $question)) { $output->writeln("<comment>Action cancelled.</comment>"); return; } } $helper->saveCurrentConfig($config_name); }
/** * {@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) { $helper = new ConfigHelper(); $configsets = array_keys($helper->getAllConfigSets()); $output->writeln("<comment>Available config sets:</comment>"); foreach ($configsets as $set) { $output->writeln("<info>{$set}</info>"); } }
/** * {@inheritdoc} */ public function execute(InputInterface $input, OutputInterface $output) { // TODO: Ensure that configurations have been initialized // Get available config sets $helper = new ConfigHelper(); $configsets = $helper->getAllConfigSets(); $homedir = getenv('HOME'); // Check if passed argument is 'all' $names = $input->getArgument('setting'); if (empty($names)) { // 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(s) to display:</question> "; $output->writeln($message); $message = "<comment>Separate multiple values with commas.</comment>"; $options = array_merge(array_keys($configsets), array('current', 'all')); $question = new ChoiceQuestion($message, $options, 0); $question->setMultiselect(TRUE); $names = $qhelper->ask($input, $output, $question); } if (in_array('all', $names)) { $names = array_keys($configsets); } // Is passed config set valid? foreach ($names as $key => $name) { if ($name == 'current') { $env_vars = $helper->getCurrentEnvVars(); $output->writeln("<info>---------------- Start config set: <options=bold>CURRENT DCI ENVIRONMENT</options=bold></info> ----------------</info>"); $output->writeln("<comment;options=bold>Defined in ~/.drupalci/config:</comment;options=bold>"); $contents = $helper->getCurrentConfigSetContents(); foreach ($contents as $line) { $parsed = explode("=", $line); if (!empty($parsed[0]) && !empty($parsed[1])) { $output->writeln("<comment>" . strtoupper($parsed[0]) . ": </comment><info>" . $parsed[1] . "</info>"); } } if (!empty($env_vars)) { $output->writeln("<comment;options=bold>Defined in Environment Variables:</comment;options=bold>"); foreach ($env_vars as $key => $value) { $output->writeln("<comment>" . strtoupper($key) . ": </comment><info>" . $value . "</info>"); } $output->writeln("<info>------------ End config set: <options=bold>CURRENT DCI ENVIRONMENT</options=bold></info> ----------------</info>"); $output->writeln(''); } } elseif (in_array($name, array_keys($configsets))) { $contents = file_get_contents($configsets[$name]); $output->writeln("<info>---------------- Start config set: <options=bold>{$name}</options=bold></info> ----------------</info>"); $output->writeln($contents); $output->writeln("<info>------------ End config set: <options=bold>{$name}</options=bold></info> ----------------</info>"); $output->writeln(''); } else { $output->writeln("<error>Configuration set '{$name}' not found. Skipping.</error>"); } } }
/** * {@inheritdoc} */ public function execute(InputInterface $input, OutputInterface $output) { // Get available config sets $helper = new ConfigHelper(); $qhelper = $this->getHelper('question'); $configsets = $helper->getAllConfigSets(); // Get default config sets $defaultsets = $helper->getDefaultConfigSets(); $homedir = getenv('HOME'); $configdir = $homedir . "/.drupalci/configs/"; // TODO: configdir absolute path $sourcedir = "./configsets/"; // Check if passed argument is 'all' $names = $input->getArgument('setting'); if (in_array('all', $names)) { $names = array_keys($configsets); } // Is passed config set valid? foreach ($names as $name) { // Is passed config one of the default sets? if (in_array($name, array_keys($defaultsets))) { // TODO: Prompt user (You are about to overwrite the $name configuration set. (Y/N/All) $output->writeln("<comment>This action will overwrite any local changes you have made to the <options=bold>{$name}</options=bold> configuration set.</comment>"); $question = new ConfirmationQuestion("<question>Do you wish to continue? (yes/no)</question> ", false); if (!$qhelper->ask($input, $output, $question)) { continue; } // Copy defaultset from code dir to ~/.drupalci/config $output->writeln("<comment>Resetting the <options=bold>{$name}</options=bold> configuration set.</comment>"); $file = $sourcedir . $name; copy($file, $configdir . $name); } elseif (in_array($name, array_keys($configsets))) { // TODO: Prompt user (This action will delete the $name configuration set $output->writeln("<comment>This action will delete the <options=bold>{$name}</options=bold> configuration set.</comment>"); $question = new ConfirmationQuestion("<question>Do you wish to continue? (yes/no)</question> ", false); if (!$qhelper->ask($input, $output, $question)) { continue; } // Delete configset file $file = $configdir . $name; unlink($file); } else { // TODO: Prompt user (Invalid configuration set) $output->writeln("<error>The '{$name}' configuration set does not exist.</error></comment>"); } } }