From 1031079c92b7968da13600e600729e6b2fe4ea0b Mon Sep 17 00:00:00 2001 From: mokaddem Date: Wed, 13 Jan 2021 15:19:26 +0100 Subject: [PATCH] chg: [command:updater] Draft of manual updater script --- src/Command/UpdaterCommand.php | 62 ++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/Command/UpdaterCommand.php diff --git a/src/Command/UpdaterCommand.php b/src/Command/UpdaterCommand.php new file mode 100644 index 0000000..6a57689 --- /dev/null +++ b/src/Command/UpdaterCommand.php @@ -0,0 +1,62 @@ + 'metaTemplateV2', + ]; + + protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser + { + $parser->setDescription('Execute updates.'); + $parser->addArgument('updateName', [ + 'help' => 'The name of the update to execute', + 'required' => false, + 'choices' => array_keys($this->availableUpdates) + ]); + return $parser; + } + + public function execute(Arguments $args, ConsoleIo $io) + { + $this->io = $io; + $targetUpdateName = $args->getArgument('updateName'); + + if (!in_array($targetUpdateName, array_keys($this->availableUpdates))) { + $io->out('Available updates:'); + $io->helper('Table')->output($this->listAvailableUpdates()); + die(1); + } + + $selection = $io->askChoice("Do you wish to apply update `{$targetUpdateName}`?", ['Y', 'N'], 'N'); + if ($selection == 'Y') { + $updateFunction = $this->availableUpdates[$targetUpdateName]; + $updateResult = $this->{$updateFunction}(); + $io->out('Update ' . ($updateResult ? 'successful' : 'fail')); + } else { + $io->out('Update canceled'); + } + } + + private function listAvailableUpdates() + { + $list = [['Update name']]; + foreach ($this->availableUpdates as $updateName => $f) { + $list[] = [$updateName]; + } + return $list; + } + + private function metaTemplateV2() + { + return true; + } +} \ No newline at end of file