/**
  * {@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)
 {
     $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)
 {
     // Retrieve passed argument
     $arguments = $input->getArgument('variable');
     $helper = new ConfigHelper();
     // Retrieve current config
     $config = $helper->getCurrentConfigSetParsed();
     foreach ($arguments as $argument) {
         // Check that the variable exists
         if (!array_key_exists($argument, $config)) {
             $output->writeln("<info>The <option=bold>{$argument}</option=bold> variable does not exist.  No action taken.");
         } else {
             // Prompt the user that this will overwrite the existing setting
             $qhelper = $this->getHelper('question');
             $output->writeln("<info>This will remove the <option=bold>{$argument}</option=bold> variable from your current configuration set.</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->clearConfigVariable($argument);
             $output->writeln("<comment>The <info>{$argument}</info> variable has been deleted from the current config set.</comment>");
         }
     }
 }
 /**
  * {@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>");
     }
 }
 /**
  * {@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>");
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     // Retrieve passed argument
     $arguments = $input->getArgument('assignment');
     $helper = new ConfigHelper();
     // Retrieve current config
     $config = $helper->getCurrentConfigSetParsed();
     foreach ($arguments as $argument) {
         // Parse key => value
         $parsed = explode('=', $argument);
         if (count($parsed) != 2) {
             $output->writeln("<error>Unable to parse argument.</error>");
             $output->writeln("<comment>Please provide both a variable name and value formatted as <options=bold>variable_name=variable_value</options=bold></comment>");
             return;
         }
         // TODO: Validate key against a list of allowed variables
         $key = trim($parsed[0]);
         $value = trim($parsed[1]);
         // Check if replacing an existing environment variable
         if ($existing = getenv($key)) {
             // Prompt the user that an existing environment variable exists and can not be overwritten
             $output->writeln("<error>The <option=bold>{$key}</option=bold> setting has been set via an environment variable and can not be set via the console.</error>");
             $output->writeln("<comment>To override this value, provide it on the command line as part of the drupalci invocation.");
             $output->writeln("<comment>Example: </comment> {$key}={$value} ./drupalci [command]");
         } elseif (in_array($key, array_keys($config))) {
             // Prompt the user that this will overwrite the existing setting
             $qhelper = $this->getHelper('question');
             $output->writeln("<info>The <option=bold>{$key}</option=bold> variable already exists.</info>");
             $message = "<question>Are you sure you wish to override it? (yes/no)</question> ";
             $question = new ConfirmationQuestion($message, false);
             if (!$qhelper->ask($input, $output, $question)) {
                 $output->writeln("<comment>Action cancelled.</comment>");
                 return;
             }
             $helper->setConfigVariable($key, $value);
         } else {
             // Set the var and provide feedback
             $output->writeln("<info>Setting the value of the <option=bold>{$key}</option=bold> variable to <option=bold>{$value}</option=bold>");
             $helper->setConfigVariable($key, $value);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function run(JobInterface $job, $data = NULL)
 {
     // Get and parse test definitions
     // DrupalCI jobs are controlled via a hierarchy of configuration settings, which define the behaviour of the platform while running DrupalCI jobs.  This hierarchy is defined as follows, which each level overriding the previous:
     // 1. Out-of-the-box DrupalCI defaults
     // 2. Local overrides defined in ~/.drupalci/config
     // 3. 'DCI_' namespaced environment variable overrides
     // 4. Test-specific overrides passed inside a DrupalCI test definition (e.g. .drupalci.yml)
     // 5. Custom overrides located inside a test definition defined via the $source variable when calling this function.
     $confighelper = new ConfigHelper();
     // Load job defaults
     $platform_args = $job->getPlatformDefaults();
     $default_args = $job->getDefaultArguments();
     if (!empty($default_args)) {
         $job->getOutput()->writeln("<comment>Loading build variables for this job type.</comment>");
     }
     // Load DrupalCI local config overrides
     $local_args = $confighelper->getCurrentConfigSetParsed();
     if (!empty($local_args)) {
         $job->getOutput()->writeln("<comment>Loading build variables from DrupalCI local config overrides.</comment>");
     }
     // Load "DCI_ namespaced" environment variable overrides
     $environment_args = $confighelper->getCurrentEnvVars();
     if (!empty($environment_args)) {
         $job->getOutput()->writeln("<comment>Loading build variables from namespaced environment variable overrides.</comment>");
     }
     // Load command line arguments
     // TODO: Routine for loading command line arguments.
     // TODO: How do we pull arguments off the drupalci command, when in a job class?
     // $cli_args = $somehelper->loadCLIargs();
     $cli_args = array();
     if (!empty($cli_args)) {
         $job->getOutput()->writeln("<comment>Loading test parameters from command line arguments.</comment>");
     }
     // Create temporary config array to use in determining the definition file source
     $config = $cli_args + $environment_args + $local_args + $default_args + $platform_args;
     // Load any build vars defined in the job definition file
     // Retrieve test definition file
     if (isset($source)) {
         $config['explicit_source'] = $source;
     }
     $definition_file = $this->getDefinitionFile($config);
     $definition_args = array();
     // Load test definition file
     if (!empty($definition_file)) {
         $job->getOutput()->writeln("<comment>Loading test parameters from build file: </comment><info>{$definition_file}</info>");
         $jobdef = new JobDefinition();
         $result = $jobdef->load($definition_file);
         if ($result == -1) {
             // Error loading definition file.
             $job->errorOutput("Failed", "Unable to parse build file.");
             // TODO: Robust error handling
             return;
         }
         $job_definition = $jobdef->getParameters();
         if (empty($job_definition)) {
             $job_definition = array();
             $definition_args = array();
         } else {
             $definition_args = !empty($job_definition['build_vars']) ? $job_definition['build_vars'] : array();
         }
         $job->setDefinition($job_definition);
     }
     $config = $cli_args + $definition_args + $environment_args + $local_args + $default_args + $platform_args;
     // Set initial build variables
     $buildvars = $job->getBuildVars();
     $job->setBuildVars($buildvars + $config);
     // Map relevant build variables into the job definition array
     // $this->buildvarsToDefinition($job);
     return;
 }