Commit 6adca5b6 authored by Jon Pugh's avatar Jon Pugh

Implementing --delete option for `provision save` command.

parent a6877169
......@@ -57,7 +57,7 @@ class SaveCommand extends Command
$inputDefinition[] = new InputOption(
'delete',
null,
InputOption::VALUE_OPTIONAL,
InputOption::VALUE_NONE,
'Remove the alias.'
);
......@@ -81,12 +81,17 @@ class SaveCommand extends Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$context_name = $this->input->getArgument('context_name');
try {
$context = $this->getApplication()->getContext($input->getArgument('context_name'));
}
catch (\Exception $e) {
$context_name = $this->input->getArgument('context_name');
if ($input->getOption('delete')) {
$this->io->comment("No context named '$context_name'.");
exit(1);
}
$this->io->comment("No context named '$context_name'. Creating a new one...");
if (empty($this->input->getOption('context_type'))) {
......@@ -102,6 +107,20 @@ class SaveCommand extends Command
$context = new $class($input->getArgument('context_name'), $this->getApplication()->getConfig()->all(), $properties);
}
// Delete context config.
if ($input->getOption('delete')) {
if (!$input->isInteractive() || $this->io->confirm("Delete context '$context_name' configuration ($context->config_path)?")) {
if ($context->deleteConfig()) {
$this->io->info('Context file deleted.');
exit(0);
}
else {
$this->io->error('Unable to delete ' . $context->config_path);
exit(1);
}
}
}
foreach ($context->getProperties() as $name => $value) {
$rows[] = [$name, $value];
}
......
......@@ -141,6 +141,23 @@ class Context
}
}
/**
* Deletes the config YML file.
* @return bool
*/
public function deleteConfig() {
// Create config folder if it does not exist.
$fs = new Filesystem();
try {
$fs->remove($this->config_path);
return true;
} catch (IOException $e) {
return false;
}
}
static function getClassName($type) {
return '\Aegir\Provision\Context\\' . ucfirst($type) . "Context";
}
......
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