Commit a10251f6 authored by Jon Pugh's avatar Jon Pugh

Add method getAllContexts() to load all context configs, and use it to list...

Add method getAllContexts() to load all context configs, and use it to list them on 'status' command.
parent 04735600
......@@ -122,4 +122,21 @@ class Application extends BaseApplication
return $inputDefinition;
}
/**
* Lookup and return all contexts as found in files.
*
* @return array
*/
function getAllContexts() {
$contexts = [];
$finder = new \Symfony\Component\Finder\Finder();
$finder->files()->name('*.yml')->in($this->config->get('config_path') . '/provision');
foreach ($finder as $file) {
list($context_type, $context_name) = explode('.', $file->getFilename());
$class = '\Aegir\Provision\Context\\' . ucfirst($context_type) . "Context";
$contexts[$context_name] = new $class($context_name, $this->config->all());
}
return $contexts;
}
}
......@@ -83,7 +83,7 @@ class SaveCommand extends Command
{
$class = '\Aegir\Provision\Context\\' . ucfirst($input->getOption('context_type')) . "Context";
$context = new $class($input->getArgument('context_name'), $input->getOptions(), $this->getApplication()->getConfig()->all());
$context = new $class($input->getArgument('context_name'),$this->getApplication()->getConfig()->all(), $input->getOptions());
foreach ($context->getProperties() as $name => $value) {
$rows[] = [$name, $value];
......
......@@ -43,5 +43,12 @@ class StatusCommand extends Command
}
$io->table($headers, $rows);
// Lookup all contexts
$rows = [];
foreach ($this->getApplication()->getAllContexts() as $context) {
$rows[] = [$context->name, $context->type];
}
$headers = ['Contexts'];
$io->table($headers, $rows);
}
}
......@@ -41,7 +41,7 @@ class Context
/**
* Constructor for the context.
*/
function __construct($name, $options, $console_config)
function __construct($name, $console_config, $options = [])
{
$this->name = $name;
......@@ -64,7 +64,7 @@ class Context
$this->properties[$option] = $options[$option];
}
}
$this->properties['context_type'] = $options['context_type'];
$this->properties['context_type'] = $this->type;
$this->config = $processor->processConfiguration($this, $configs);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment