Skip to content

Commit

Permalink
cli command return success/failure added
Browse files Browse the repository at this point in the history
  • Loading branch information
bbakalov committed Jun 19, 2023
1 parent c9b6715 commit 4466863
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 6 deletions.
5 changes: 4 additions & 1 deletion Console/Command/ConfigGetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Magento\Framework\Console\Cli;

/**
* Class ConfigGetCommand
Expand Down Expand Up @@ -189,7 +190,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // @c

if (count(array_unique($options)) === 1) {
$this->output->writeln('<comment>' . $this->getSynopsis() . '</comment>', OutputInterface::OUTPUT_NORMAL);
return;
return Cli::RETURN_FAILURE;
}

// Get Service ID
Expand Down Expand Up @@ -261,6 +262,8 @@ protected function execute(InputInterface $input, OutputInterface $output) // @c
if ($input->getOption('fastly-status')) {
$this->getFastlyStatus($this->config->isFastlyEnabled());
}

return Cli::RETURN_SUCCESS;
}

/**
Expand Down
7 changes: 6 additions & 1 deletion Console/Command/ConfigImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Magento\Framework\Console\Cli;

/**
* Class ConfigImportCommand
Expand Down Expand Up @@ -93,7 +94,8 @@ protected function execute(InputInterface $input, OutputInterface $output) // @c
$data = json_decode(file_get_contents($file));
if (!$data) {
$output->writeln("<error>Invalid file structure</error>");
return;

return Cli::RETURN_FAILURE;
}

$clone = $this->getClonedVersion();
Expand All @@ -117,7 +119,10 @@ protected function execute(InputInterface $input, OutputInterface $output) // @c

} catch (\Exception $e) {
$output->writeln("<error>{$e->getMessage()}</error>");
return Cli::RETURN_FAILURE;
}

return Cli::RETURN_SUCCESS;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Console/Command/EnableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Symfony\Component\Console\Input\InputOption;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Framework\App\Cache\Manager;
use Magento\Framework\Console\Cli;
use Magento\Framework\Filesystem;
use Magento\Framework\App\Filesystem\DirectoryList;

Expand Down Expand Up @@ -284,7 +285,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // @c

if (count(array_unique($options)) === 1) {
$this->output->writeln('<comment>' . $this->getSynopsis() . '</comment>', OutputInterface::OUTPUT_NORMAL);
return;
return Cli::RETURN_FAILURE;
}

// Set Service ID
Expand Down Expand Up @@ -389,6 +390,8 @@ protected function execute(InputInterface $input, OutputInterface $output) // @c

$arguments = new ArrayInput(['command' => 'cache:flush', 'types' => ['config']]);
$this->getApplication()->find('cache:flush')->run($arguments, $output);

return Cli::RETURN_SUCCESS;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions Console/Command/GenerateVclCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Magento\Framework\Console\Cli;

/**
* Class GenerateVclCommand
Expand Down Expand Up @@ -51,5 +52,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // @c
"Fastly custom VCL use been deprecated."
. "Please upload VCL snippets from the Magento admin UI or using the CLI commands."
);

return Cli::RETURN_SUCCESS;
}
}
4 changes: 3 additions & 1 deletion Console/Command/JsonToSerialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Framework\Console\Cli;
use Magento\Framework\Serialize\SerializerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -120,7 +121,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // @c

if ($oldData === false || $oldData === null) {
$output->writeln('Invalid JSON format, unable to decode config data : ' . $path);
return;
return Cli::RETURN_FAILURE;
}

$oldData = (is_array($oldData)) ? $oldData : [];
Expand All @@ -134,6 +135,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // @c
$this->cacheManager->clean([\Magento\Framework\App\Cache\Type\Config::TYPE_IDENTIFIER]);

$output->writeln('Config Cache Flushed');
return Cli::RETURN_SUCCESS;
}
}
}
4 changes: 3 additions & 1 deletion Console/Command/SerializeToJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Framework\Console\Cli;
use Magento\Framework\Serialize\Serializer\Serialize;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -130,7 +131,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // @c
'Invalid serialization format, unable to unserialize config data : ' . $path
);

return;
return Cli::RETURN_FAILURE;
}
$oldData = (is_array($oldData)) ? $oldData : [];

Expand All @@ -143,6 +144,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // @c
$this->cacheManager->clean([\Magento\Framework\App\Cache\Type\Config::TYPE_IDENTIFIER]);

$output->writeln('Config Cache Flushed');
return Cli::RETURN_SUCCESS;
}
}
}
5 changes: 4 additions & 1 deletion Console/Command/SuperUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Fastly\Cdn\Model\Config;
use Fastly\Cdn\Model\Api;
use Fastly\Cdn\Helper\Vcl;
use Magento\Framework\Console\Cli;
use Magento\Framework\Filesystem;
use Magento\Framework\App\Filesystem\DirectoryList;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -119,7 +120,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // @c

if (count(array_unique($options)) === 1) {
$this->output->writeln('<comment>' . $this->getSynopsis() . '</comment>', OutputInterface::OUTPUT_NORMAL);
return;
return Cli::RETURN_FAILURE;
}

if ($input->getOption('enable')) {
Expand All @@ -133,6 +134,8 @@ protected function execute(InputInterface $input, OutputInterface $output) // @c
if ($input->getOption('update')) {
$this->updateSuIps();
}

return Cli::RETURN_SUCCESS;
}

/**
Expand Down

0 comments on commit 4466863

Please sign in to comment.