summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Pugh2017-11-02 16:58:15 -0400
committerJon Pugh2017-11-02 16:58:15 -0400
commit5ad59a379195d82c58481686f9b888dbf519fe41 (patch)
tree2906b7e415b51e36571630d9b2d5fda208b43b6d
parentde7acba788b3b1bbe1b7d93297c9424a4ba2e992 (diff)
When asking which context to use, throw an exception if there are none available.4.x-cleanup
For `save` command, add "new" to the options list. When done saving server context, offer to add services in a loop allowing quick and easy setup.
-rw-r--r--src/Command.php7
-rw-r--r--src/Command/SaveCommand.php43
2 files changed, 46 insertions, 4 deletions
diff --git a/src/Command.php b/src/Command.php
index da70f9f..06be19a 100644
--- a/src/Command.php
+++ b/src/Command.php
@@ -105,11 +105,10 @@ abstract class Command extends BaseCommand
*/
public function askForContext($question = 'Choose a context') {
if (empty($this->getApplication()->getAllContextsOptions())) {
- $this->context_name = $this->io->ask('Context name');
- }
- else {
- $this->context_name = $this->io->choice($question, $this->getApplication()->getAllContextsOptions());
+ throw new \Exception('No contexts available! use <comment>provision save</comment> to create one.');
}
+
+ $this->context_name = $this->io->choice($question, $this->getApplication()->getAllContextsOptions());
}
/**
diff --git a/src/Command/SaveCommand.php b/src/Command/SaveCommand.php
index 102ec98..fcb7c9a 100644
--- a/src/Command/SaveCommand.php
+++ b/src/Command/SaveCommand.php
@@ -8,6 +8,7 @@ use Aegir\Provision\Context\PlatformContext;
use Aegir\Provision\Context\ServerContext;
use Aegir\Provision\Context\SiteContext;
use Symfony\Component\Console\Exception\InvalidOptionException;
+use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
@@ -144,11 +145,53 @@ class SaveCommand extends Command
$this->io->error("Unable to save configuration to {$this->context->config_path}. ");
}
}
+ else {
+ $this->io->warningLite('Context not saved.');
+ return;
+ }
// $command = 'drush provision-save '.$input->getArgument('context_name');
// $this->process($command);
+
+ // Offer to add services.
+ if ($this->input->isInteractive()) {
+ $command = $this->getApplication()->find('services');
+ $arguments = [
+ 'context_name' => $this->input->getArgument('context_name'),
+ 'sub_command' => 'add',
+ ];
+ while ($this->io->confirm('Add a service?')) {
+
+ $greetInput = new ArrayInput($arguments);
+ $returnCode = $command->run($greetInput, $output);
+ $returnCodes[$returnCode] = $returnCode;
+ }
+ }
}
/**
+ * Override to add options
+ * @param string $question
+ */
+ public function askForContext($question = 'Choose a context')
+ {
+ $options = $this->getApplication()->getAllContextsOptions();
+
+ // If there are options, add "new" to the list.
+ if (count($options)) {
+ $options['new'] = 'Create a new context.';
+ $this->context_name = $this->io->choice($question, $options);
+
+ if ($this->context_name == 'new') {
+ $this->context_name = $this->io->ask('Context name');
+ }
+ }
+ // If there are no options, just ask for the name to create.
+ else {
+ $this->context_name = $this->io->ask('Context name');
+ }
+ }
+
+ /**
* Loop through this context type's option_documentation() method and ask for each property.
*
* @return array