From a6acd8bed832d15fbc779cff779200d35f0e9419 Mon Sep 17 00:00:00 2001 From: kostiantyn Date: Wed, 29 Nov 2023 15:22:51 +0100 Subject: [PATCH] Add --tag option for the apply commnad --- shipyard.example.yaml | 3 +-- shipyard.yaml | 3 +-- src/Command/ApplyCommand.php | 14 +++++++++++++- src/Stack.php | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/shipyard.example.yaml b/shipyard.example.yaml index 76277b5..c88626b 100644 --- a/shipyard.example.yaml +++ b/shipyard.example.yaml @@ -24,5 +24,4 @@ settings: # Target connection. Values: remote/local target: remote # Template directory path on the remote host - stack_path: /opt/shipyard/stacks - shipyard_tag: apps \ No newline at end of file + stack_path: /opt/shipyard/stacks \ No newline at end of file diff --git a/shipyard.yaml b/shipyard.yaml index 55839d8..0153724 100644 --- a/shipyard.yaml +++ b/shipyard.yaml @@ -29,5 +29,4 @@ settings: # Target connection. Values: remote/local target: remote # Template directory path on the remote host - stack_path: /opt/shipyard/stacks - shipyard_tag: apps \ No newline at end of file + stack_path: /opt/shipyard/stacks \ No newline at end of file diff --git a/src/Command/ApplyCommand.php b/src/Command/ApplyCommand.php index 25a1ba0..4d7fd8d 100644 --- a/src/Command/ApplyCommand.php +++ b/src/Command/ApplyCommand.php @@ -7,6 +7,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor; use Symfony\Component\Serializer\Encoder\YamlEncoder; use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer; @@ -32,6 +33,16 @@ public function execute(InputInterface $input, OutputInterface $output) $config = $serializer->deserialize(file_get_contents('shipyard.yaml'), ShipyardModel::class, 'yaml'); + $tag = $input->getOption('tag') ? $input->getOption('tag') : False; + $settings = $config->getSettings(); + + if($tag) { + $settings->setShipyardTag($tag); + } else { + $settings->setShipyardTag(false); + } + $config->setSettings($settings); + $shipyard = new Shipyard($config, $output); $shipyard->apply(); @@ -43,7 +54,8 @@ protected function configure() { $this ->setName('apply') - ->setDescription('Shipyard apply'); + ->setDescription('Shipyard apply') + ->addOption('tag', 't', InputOption::VALUE_OPTIONAL, 'Tag for stacks to run'); } } diff --git a/src/Stack.php b/src/Stack.php index daed43c..1f13be3 100644 --- a/src/Stack.php +++ b/src/Stack.php @@ -122,7 +122,7 @@ private function twigTemplateFile($filename, $dirPath) */ public function run() { - if ($this->model->getTag() != $this->getSettings()->getShipyardTag()) { + if ($this->getSettings()->getShipyardTag() && $this->model->getTag() != $this->getSettings()->getShipyardTag()) { $this->output->writeln(sprintf( '- Skip stack `%s(%s)` because of tag difference.', $this->model->getName(),