Skip to content

Commit

Permalink
Removed the type argument in console commands
Browse files Browse the repository at this point in the history
  • Loading branch information
sebprt committed Oct 31, 2023
1 parent 47e195a commit 2c7ca16
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 38 deletions.
21 changes: 7 additions & 14 deletions src/Cloud/Console/Command/CreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
16 changes: 4 additions & 12 deletions src/Cloud/Console/Command/RemoveCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
16 changes: 4 additions & 12 deletions src/Cloud/Console/Command/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 2c7ca16

Please sign in to comment.