diff --git a/src/Cloud/Console/Command/CreateCommand.php b/src/Cloud/Console/Command/CreateCommand.php index 1c2071ba..b7c20564 100644 --- a/src/Cloud/Console/Command/CreateCommand.php +++ b/src/Cloud/Console/Command/CreateCommand.php @@ -23,7 +23,6 @@ protected function configure(): void $this->addOption('beta', mode: Console\Input\InputOption::VALUE_NONE, description: 'Shortcut to set the cloud instance to https://beta.gyroscops.com'); $this->addOption('ssl', mode: Console\Input\InputOption::VALUE_NEGATABLE, description: 'Enable or disable SSL'); $this->addArgument('config', Console\Input\InputArgument::REQUIRED); - $this->addArgument('type', Console\Input\InputArgument::REQUIRED, 'Type of runtime (pipeline ou workflow)'); } protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int @@ -63,13 +62,6 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } } - $type = $input->getArgument('type'); - if ('pipeline' !== $type && 'workflow' !== $type) { - $output->writeln('The type must be either "pipeline" or "workflow".'); - - return Console\Command\Command::FAILURE; - } - for ($directory = getcwd(); '/' !== $directory; $directory = \dirname($directory)) { if (file_exists($directory.'/.gyro.php')) { break; @@ -136,13 +128,14 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O $context = new Satellite\Cloud\Context($client, $auth, $url); - $instance = match ($type) { - ArgumentType::PIPELINE->value => new Satellite\Cloud\Pipeline($context), - ArgumentType::WORKFLOW->value => new Satellite\Cloud\Workflow($context), - default => throw new \InvalidArgumentException('Invalid type provided.'), - }; + foreach ($configuration['satellites'] as $code => $satellite) { + $satellite['code'] = $code; + $instance = match (true) { + array_key_exists('pipeline', $satellite) => new Satellite\Cloud\Pipeline($context), + array_key_exists('workflow', $satellite) => new Satellite\Cloud\Workflow($context), + default => throw new \RuntimeException('Invalid runtime satellite configuration.'), + }; - foreach ($configuration['satellites'] as $satellite) { foreach ($instance->create($instance::fromLegacyConfiguration($satellite)) as $command) { $bus->push($command); } diff --git a/src/Cloud/Console/Command/RemoveCommand.php b/src/Cloud/Console/Command/RemoveCommand.php index 8e9ad494..5dfef83b 100644 --- a/src/Cloud/Console/Command/RemoveCommand.php +++ b/src/Cloud/Console/Command/RemoveCommand.php @@ -23,7 +23,6 @@ protected function configure(): void $this->addOption('beta', mode: Console\Input\InputOption::VALUE_NONE, description: 'Shortcut to set the cloud instance to https://beta.gyroscops.com'); $this->addOption('ssl', mode: Console\Input\InputOption::VALUE_NEGATABLE, description: 'Enable or disable SSL'); $this->addArgument('config', mode: Console\Input\InputArgument::REQUIRED); - $this->addArgument('type', mode: Console\Input\InputArgument::REQUIRED, description: 'Type of runtime (pipeline ou workflow)'); } protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int @@ -60,13 +59,6 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } } - $type = $input->getArgument('type'); - if ('pipeline' !== $type && 'workflow' !== $type) { - $output->writeln('The type must be either "pipeline" or "workflow".'); - - return Console\Command\Command::FAILURE; - } - for ($directory = getcwd(); '/' !== $directory; $directory = \dirname($directory)) { if (file_exists($directory.'/.gyro.php')) { break; @@ -131,10 +123,10 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } $context = new Satellite\Cloud\Context($client, $auth, $url); - $instance = match ($type) { - ArgumentType::PIPELINE->value => new Satellite\Cloud\Pipeline($context), - ArgumentType::WORKFLOW->value => new Satellite\Cloud\Workflow($context), - default => throw new \InvalidArgumentException('Invalid type provided.'), + $instance = match (true) { + array_key_exists('pipeline', $configuration) => new Satellite\Cloud\Pipeline($context), + array_key_exists('workflow', $configuration) => new Satellite\Cloud\Workflow($context), + default => throw new \RuntimeException('Invalid runtime satellite configuration.'), }; foreach ($instance->remove($instance::fromApiWithCode($client, array_key_first($configuration['satellites']))->id()) as $command) { diff --git a/src/Cloud/Console/Command/UpdateCommand.php b/src/Cloud/Console/Command/UpdateCommand.php index 669d4a2f..313c6870 100644 --- a/src/Cloud/Console/Command/UpdateCommand.php +++ b/src/Cloud/Console/Command/UpdateCommand.php @@ -23,7 +23,6 @@ protected function configure(): void $this->addOption('beta', mode: Console\Input\InputOption::VALUE_NONE, description: 'Shortcut to set the cloud instance to https://beta.gyroscops.com'); $this->addOption('ssl', mode: Console\Input\InputOption::VALUE_NEGATABLE, description: 'Enable or disable SSL'); $this->addArgument('config', Console\Input\InputArgument::REQUIRED); - $this->addArgument('type', Console\Input\InputArgument::REQUIRED, 'Type of runtime (pipeline ou workflow)'); } protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int @@ -63,13 +62,6 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } } - $type = $input->getArgument('type'); - if ('pipeline' !== $type && 'workflow' !== $type) { - $output->writeln('The type must be either "pipeline" or "workflow.'); - - return Console\Command\Command::FAILURE; - } - for ($directory = getcwd(); '/' !== $directory; $directory = \dirname($directory)) { if (file_exists($directory.'/.gyro.php')) { break; @@ -134,10 +126,10 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } $context = new Satellite\Cloud\Context($client, $auth, $url); - $instance = match ($type) { - ArgumentType::PIPELINE->value => new Satellite\Cloud\Pipeline($context), - ArgumentType::WORKFLOW->value => new Satellite\Cloud\Workflow($context), - default => throw new \InvalidArgumentException('Invalid type provided.'), + $instance = match (true) { + array_key_exists('pipeline', $configuration) => new Satellite\Cloud\Pipeline($context), + array_key_exists('workflow', $configuration) => new Satellite\Cloud\Workflow($context), + default => throw new \RuntimeException('Invalid runtime satellite configuration.'), }; foreach ($instance->update($instance::fromApiWithCode($client, array_key_first($configuration['satellites'])), $instance::fromLegacyConfiguration($configuration['satellite'])) as $command) {