summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Pugh2017-10-18 14:38:52 (GMT)
committerJon Pugh2017-10-18 14:38:52 (GMT)
commitd713af8b6ce28c859c413d8b1ec6bb3abe368cee (patch)
tree7d302d73ec1995f09dfe5a41ea639c34fe5ebc5c
parent46111b2bac3aabf3f2df6b108347e2c065ca23fa (diff)
Use options_documentation() on service classes as set of questions to ask when adding a service.
-rw-r--r--src/Command/ServicesCommand.php27
-rw-r--r--src/Context/ServerContext.php2
2 files changed, 28 insertions, 1 deletions
diff --git a/src/Command/ServicesCommand.php b/src/Command/ServicesCommand.php
index d02ed26..1ed7d8f 100644
--- a/src/Command/ServicesCommand.php
+++ b/src/Command/ServicesCommand.php
@@ -123,6 +123,9 @@ class ServicesCommand extends Command
// Then ask which service type
$service_type = $this->io->choice('Which service type?', $this->context->getServiceTypeOptions($service));
+ // Then ask for all options.
+ $properties = $this->askForServiceProperties($service);
+
$this->io->info("Adding $service service $service_type...");
try {
@@ -136,4 +139,28 @@ class ServicesCommand extends Command
throw new \Exception("Something went wrong when saving the context: " . $e->getMessage());
}
}
+
+ /**
+ * Loop through this context type's option_documentation() method and ask for each property.
+ *
+ * @return array
+ */
+ private function askForServiceProperties($service) {
+
+ $class = $this->context->getAvailableServices($service);
+
+ $options = $class::option_documentation();
+ $properties = [];
+ foreach ($options as $name => $description) {
+ // If option does not exist, ask for it.
+ if (!empty($this->input->hasOption($name))) {
+ $properties[$name] = $this->input->getOption($name);
+ $this->io->comment("Using option {$name}={$properties[$name]}");
+ }
+ else {
+ $properties[$name] = $this->io->ask("$name ($description)");
+ }
+ }
+ return $properties;
+ }
}
diff --git a/src/Context/ServerContext.php b/src/Context/ServerContext.php
index 8bb3ff4..1039c73 100644
--- a/src/Context/ServerContext.php
+++ b/src/Context/ServerContext.php
@@ -61,7 +61,7 @@ class ServerContext extends Context implements ConfigurationInterface
*
* @return array
*/
- protected function getAvailableServices($service = NULL) {
+ public function getAvailableServices($service = NULL) {
// Load all service classes
$classes = [];