Skip to content

Commit 5ba5819

Browse files
authored
Merge pull request #643 from bbakalov/fix/cli-command-return-type
cli command return success/failure added
2 parents c922ed6 + 4466863 commit 5ba5819

File tree

7 files changed

+27
-6
lines changed

7 files changed

+27
-6
lines changed

Console/Command/ConfigGetCommand.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Symfony\Component\Console\Input\InputInterface;
2828
use Symfony\Component\Console\Output\OutputInterface;
2929
use Symfony\Component\Console\Input\InputOption;
30+
use Magento\Framework\Console\Cli;
3031

3132
/**
3233
* Class ConfigGetCommand
@@ -189,7 +190,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // @c
189190

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

195196
// Get Service ID
@@ -261,6 +262,8 @@ protected function execute(InputInterface $input, OutputInterface $output) // @c
261262
if ($input->getOption('fastly-status')) {
262263
$this->getFastlyStatus($this->config->isFastlyEnabled());
263264
}
265+
266+
return Cli::RETURN_SUCCESS;
264267
}
265268

266269
/**

Console/Command/ConfigImportCommand.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Symfony\Component\Console\Input\InputInterface;
2626
use Symfony\Component\Console\Output\OutputInterface;
2727
use Symfony\Component\Console\Input\InputOption;
28+
use Magento\Framework\Console\Cli;
2829

2930
/**
3031
* Class ConfigImportCommand
@@ -93,7 +94,8 @@ protected function execute(InputInterface $input, OutputInterface $output) // @c
9394
$data = json_decode(file_get_contents($file));
9495
if (!$data) {
9596
$output->writeln("<error>Invalid file structure</error>");
96-
return;
97+
98+
return Cli::RETURN_FAILURE;
9799
}
98100

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

118120
} catch (\Exception $e) {
119121
$output->writeln("<error>{$e->getMessage()}</error>");
122+
return Cli::RETURN_FAILURE;
120123
}
124+
125+
return Cli::RETURN_SUCCESS;
121126
}
122127

123128
/**

Console/Command/EnableCommand.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use Symfony\Component\Console\Input\InputOption;
3131
use Magento\Framework\App\Config\Storage\WriterInterface;
3232
use Magento\Framework\App\Cache\Manager;
33+
use Magento\Framework\Console\Cli;
3334
use Magento\Framework\Filesystem;
3435
use Magento\Framework\App\Filesystem\DirectoryList;
3536

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

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

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

390391
$arguments = new ArrayInput(['command' => 'cache:flush', 'types' => ['config']]);
391392
$this->getApplication()->find('cache:flush')->run($arguments, $output);
393+
394+
return Cli::RETURN_SUCCESS;
392395
}
393396

394397
/**

Console/Command/GenerateVclCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Symfony\Component\Console\Command\Command;
2424
use Symfony\Component\Console\Input\InputInterface;
2525
use Symfony\Component\Console\Output\OutputInterface;
26+
use Magento\Framework\Console\Cli;
2627

2728
/**
2829
* Class GenerateVclCommand
@@ -51,5 +52,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // @c
5152
"Fastly custom VCL use been deprecated."
5253
. "Please upload VCL snippets from the Magento admin UI or using the CLI commands."
5354
);
55+
56+
return Cli::RETURN_SUCCESS;
5457
}
5558
}

Console/Command/JsonToSerialize.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Magento\Framework\App\Config\ScopeConfigInterface;
2525
use Magento\Framework\App\Config\Storage\WriterInterface;
2626
use Magento\Framework\App\ProductMetadataInterface;
27+
use Magento\Framework\Console\Cli;
2728
use Magento\Framework\Serialize\SerializerInterface;
2829
use Symfony\Component\Console\Command\Command;
2930
use Symfony\Component\Console\Input\InputInterface;
@@ -120,7 +121,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // @c
120121

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

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

136137
$output->writeln('Config Cache Flushed');
138+
return Cli::RETURN_SUCCESS;
137139
}
138140
}
139141
}

Console/Command/SerializeToJson.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Magento\Framework\App\Config\ScopeConfigInterface;
2525
use Magento\Framework\App\Config\Storage\WriterInterface;
2626
use Magento\Framework\App\ProductMetadataInterface;
27+
use Magento\Framework\Console\Cli;
2728
use Magento\Framework\Serialize\Serializer\Serialize;
2829
use Symfony\Component\Console\Command\Command;
2930
use Symfony\Component\Console\Input\InputInterface;
@@ -130,7 +131,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // @c
130131
'Invalid serialization format, unable to unserialize config data : ' . $path
131132
);
132133

133-
return;
134+
return Cli::RETURN_FAILURE;
134135
}
135136
$oldData = (is_array($oldData)) ? $oldData : [];
136137

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

145146
$output->writeln('Config Cache Flushed');
147+
return Cli::RETURN_SUCCESS;
146148
}
147149
}
148150
}

Console/Command/SuperUserCommand.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Fastly\Cdn\Model\Config;
2424
use Fastly\Cdn\Model\Api;
2525
use Fastly\Cdn\Helper\Vcl;
26+
use Magento\Framework\Console\Cli;
2627
use Magento\Framework\Filesystem;
2728
use Magento\Framework\App\Filesystem\DirectoryList;
2829
use Symfony\Component\Console\Command\Command;
@@ -119,7 +120,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // @c
119120

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

125126
if ($input->getOption('enable')) {
@@ -133,6 +134,8 @@ protected function execute(InputInterface $input, OutputInterface $output) // @c
133134
if ($input->getOption('update')) {
134135
$this->updateSuIps();
135136
}
137+
138+
return Cli::RETURN_SUCCESS;
136139
}
137140

138141
/**

0 commit comments

Comments
 (0)