Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[console] Add missing return error codes. #3291

Merged
merged 1 commit into from
May 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Annotations/DrupalCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* @Annotation
* @Target("CLASS")
*/

class DrupalCommand
{
/**
Expand Down
8 changes: 6 additions & 2 deletions src/Command/Config/EditCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (!$configName) {
$io->error($this->trans('commands.config.edit.messages.no-config'));

return;
return 1;
}

try {
Expand All @@ -106,7 +106,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
} catch (IOExceptionInterface $e) {
$io->error($this->trans('commands.config.edit.messages.no-directory').' '.$e->getPath());

return;
return 1;
}
if (!$editor) {
$editor = $this->getEditor();
Expand All @@ -122,9 +122,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
$config->save();
$fileSystem->remove($configFile);
}

if (!$process->isSuccessful()) {
$io->error($process->getErrorOutput());
return 1;
}

return 0;
}

protected function interact(InputInterface $input, OutputInterface $output)
Expand Down
42 changes: 24 additions & 18 deletions src/Command/ContainerDebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ protected function execute(InputInterface $input, OutputInterface $output)

return 0;
} else {

$tableHeader = [];
if ($service) {
$tableRows = $this->getServiceDetail($service);
Expand All @@ -101,13 +100,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
return 0;
}

private function getCallbackReturnList($service, $method, $args) {

if ($args != NULL) {
$parsedArgs = json_decode($args, TRUE);
if (!is_array($parsedArgs)) $parsedArgs = explode(",", $args);
private function getCallbackReturnList($service, $method, $args)
{
if ($args != null) {
$parsedArgs = json_decode($args, true);
if (!is_array($parsedArgs)) {
$parsedArgs = explode(",", $args);
}
} else {
$parsedArgs = NULL;
$parsedArgs = null;
}
$serviceInstance = \Drupal::service($service);

Expand All @@ -124,7 +125,7 @@ private function getCallbackReturnList($service, $method, $args) {
'<fg=green>'.$this->trans('commands.container.debug.messages.class').'</>',
'<fg=yellow>'.get_class($serviceInstance).'</>'
];
$methods = array($method);
$methods = [$method];
$this->extendArgumentList($serviceInstance, $methods);
$serviceDetail[] = [
'<fg=green>'.$this->trans('commands.container.debug.messages.method').'</>',
Expand All @@ -133,10 +134,10 @@ private function getCallbackReturnList($service, $method, $args) {
if ($parsedArgs) {
$serviceDetail[] = [
'<fg=green>'.$this->trans('commands.container.debug.messages.arguments').'</>',
json_encode($parsedArgs, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE )
json_encode($parsedArgs, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)
];
}
$return = call_user_func_array(array($serviceInstance,$method), $parsedArgs);
$return = call_user_func_array([$serviceInstance,$method], $parsedArgs);
$serviceDetail[] = [
'<fg=green>'.$this->trans('commands.container.debug.messages.return').'</>',
json_encode($return, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)
Expand All @@ -152,10 +153,11 @@ private function getServiceList()
foreach ($serviceDefinitions as $serviceId => $serviceDefinition) {
$services[] = [$serviceId, $serviceDefinition->getClass()];
}
usort($services, array($this, 'compareService'));
usort($services, [$this, 'compareService']);
return $services;
}
private function compareService($a, $b) {
private function compareService($a, $b)
{
return strcmp($a[0], $b[0]);
}

Expand Down Expand Up @@ -208,16 +210,17 @@ private function getServiceDetail($service)

return $serviceDetail;
}
private function extendArgumentList($serviceInstance, &$methods) {
private function extendArgumentList($serviceInstance, &$methods)
{
foreach ($methods as $k => $m) {
$reflection = new \ReflectionMethod($serviceInstance, $m);
$params = $reflection->getParameters();
$p = array();
$p = [];

for ($i = 0; $i < count($params) ; $i++) {
for ($i = 0; $i < count($params); $i++) {
if ($params[$i]->isDefaultValueAvailable()) {
$defaultVar = $params[$i]->getDefaultValue();
$defaultVar = " = <fg=magenta>".str_replace(array("\n","array ("), array("", "array("), var_export($def,true)).'</>';
$defaultVar = " = <fg=magenta>".str_replace(["\n","array ("], ["", "array("], var_export($def, true)).'</>';
} else {
$defaultVar = '';
}
Expand All @@ -230,8 +233,11 @@ private function extendArgumentList($serviceInstance, &$methods) {
} else {
$defaultType = '';
}
if ($params[$i]->isPassedByReference()) $parameterReference = '<fg=yellow>&</>';
else $parameterReference = '';
if ($params[$i]->isPassedByReference()) {
$parameterReference = '<fg=yellow>&</>';
} else {
$parameterReference = '';
}
$p[] = $defaultType.$parameterReference.'<fg=red>'.'$</><fg=red>'.$params[$i]->getName().'</>'.$defaultVar;
}
if ($reflection->isPublic()) {
Expand Down
4 changes: 3 additions & 1 deletion src/Command/Generate/AuthenticationProviderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,16 @@ protected function execute(InputInterface $input, OutputInterface $output)

// @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
if (!$this->confirmGeneration($io)) {
return;
return 1;
}

$module = $input->getOption('module');
$class = $input->getOption('class');
$provider_id = $input->getOption('provider-id');

$this->generator->generate($module, $class, $provider_id);

return 0;
}

protected function interact(InputInterface $input, OutputInterface $output)
Expand Down
4 changes: 3 additions & 1 deletion src/Command/Generate/BreakPointCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

// @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
if (!$this->confirmGeneration($io)) {
return;
return 1;
}

$validators = $this->validator;
Expand All @@ -132,6 +132,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$breakpoints,
$machine_name
);

return 0;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Generate/CacheContextCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

// @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
if (!$this->confirmGeneration($io)) {
return;
return 1;
}

$module = $input->getOption('module');
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Generate/CommandCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

// @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
if (!$this->confirmGeneration($io, $yes)) {
return;
return 1;
}

// @see use Drupal\Console\Command\Shared\ServicesTrait::buildServices
Expand Down
5 changes: 3 additions & 2 deletions src/Command/Generate/ControllerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,9 @@ protected function execute(InputInterface $input, OutputInterface $output)

// @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
if (!$this->confirmGeneration($io, $yes)) {
return;
return 1;
}

$learning = $input->hasOption('learning')?$input->getOption('learning'):false;
$module = $input->getOption('module');
$class = $input->getOption('class');
$routes = $input->getOption('routes');
Expand All @@ -164,6 +163,8 @@ protected function execute(InputInterface $input, OutputInterface $output)

// Run cache rebuild to see changes in Web UI
$this->chainQueue->addCommand('router:rebuild', []);

return 0;
}

/**
Expand Down
9 changes: 4 additions & 5 deletions src/Command/Generate/EntityBundleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Drupal\Console\Command\Shared\ModuleTrait;
use Drupal\Console\Command\Shared\ServicesTrait;
use Drupal\Console\Core\Command\Shared\CommandTrait;
use Drupal\Console\Generator\ContentTypeGenerator;
use Drupal\Console\Generator\EntityBundleGenerator;
use Drupal\Console\Core\Style\DrupalStyle;
use Drupal\Console\Extension\Manager;
Expand All @@ -28,7 +27,6 @@ class EntityBundleCommand extends Command
use ServicesTrait;
use ConfirmationTrait;


/**
* @var Validator
*/
Expand Down Expand Up @@ -93,18 +91,19 @@ protected function execute(InputInterface $input, OutputInterface $output)

// @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
if (!$this->confirmGeneration($io)) {
return;
return 1;
}

$module = $input->getOption('module');
$bundleName = $input->getOption('bundle-name');
$bundleTitle = $input->getOption('bundle-title');
$learning = $input->hasOption('learning')?$input->getOption('learning'):false;

$generator = $this->generator;
//TODO:
//$generator->setLearning($learning);
// $generator->setLearning($learning);
$generator->generate($module, $bundleName, $bundleTitle);

return 0;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Generate/EventSubscriberCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

// @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
if (!$this->confirmGeneration($io)) {
return;
return 1;
}

$module = $input->getOption('module');
Expand Down
4 changes: 3 additions & 1 deletion src/Command/Generate/FormAlterCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

// @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
if (!$this->confirmGeneration($io)) {
return;
return 1;
}

$module = $input->getOption('module');
Expand Down Expand Up @@ -193,6 +193,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
->generate($module, $formId, $inputs, $this->metadata);

$this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']);

return 0;
}

protected function interact(InputInterface $input, OutputInterface $output)
Expand Down
4 changes: 3 additions & 1 deletion src/Command/Generate/HelpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

// @see use Drupal\Console\Command\ConfirmationTrait::confirmGeneration
if (!$this->confirmGeneration($io)) {
return;
return 1;
}

$module = $input->getOption('module');
Expand All @@ -118,6 +118,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
->generate($module, $description);

$this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']);

return 0;
}

protected function interact(InputInterface $input, OutputInterface $output)
Expand Down
6 changes: 4 additions & 2 deletions src/Command/Generate/ModuleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

// @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
if (!$this->confirmGeneration($io, $yes)) {
return;
return 1;
}

$module = $this->validator->validateModuleName($input->getOption('module'));
Expand Down Expand Up @@ -214,6 +214,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$test,
$twigTemplate
);

return 0;
}

/**
Expand All @@ -233,7 +235,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
} catch (\Exception $error) {
$io->error($error->getMessage());

return;
return 1;
}

if (!$module) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Generate/ModuleFileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

// @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
if (!$this->confirmGeneration($io, $yes)) {
return;
return 1;
}

$machine_name = $input->getOption('module');
Expand Down
4 changes: 3 additions & 1 deletion src/Command/Generate/PluginCKEditorButtonCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

// @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
if (!$this->confirmGeneration($io)) {
return;
return 1;
}

$module = $input->getOption('module');
Expand All @@ -138,6 +138,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
->generate($module, $class_name, $label, $plugin_id, $button_name, $button_icon_path);

$this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery'], false);

return 0;
}

protected function interact(InputInterface $input, OutputInterface $output)
Expand Down
4 changes: 3 additions & 1 deletion src/Command/Generate/PluginConditionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

// @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
if (!$this->confirmGeneration($io)) {
return;
return 1;
}

$module = $input->getOption('module');
Expand All @@ -147,6 +147,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
->generate($module, $class_name, $label, $plugin_id, $context_definition_id, $context_definition_label, $context_definition_required);

$this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']);

return 0;
}

protected function interact(InputInterface $input, OutputInterface $output)
Expand Down
4 changes: 3 additions & 1 deletion src/Command/Generate/PluginFieldCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

// @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
if (!$this->confirmGeneration($io)) {
return;
return 1;
}

$this->chainQueue
Expand Down Expand Up @@ -196,6 +196,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
);

$this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery'], false);

return 0;
}

protected function interact(InputInterface $input, OutputInterface $output)
Expand Down
Loading