Skip to content

Commit cfe0854

Browse files
committed
Merge github.com:hechoendrupal/drupal-console
2 parents dfec9d5 + 8e3dcec commit cfe0854

9 files changed

Lines changed: 268 additions & 143 deletions

File tree

src/Command/Config/EditCommand.php

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Symfony\Component\Console\Input\InputInterface;
1212
use Symfony\Component\Console\Output\OutputInterface;
1313
use Symfony\Component\Filesystem\Filesystem;
14-
use Symfony\Component\Process\ProcessBuilder;
14+
use Symfony\Component\Process\Process;
1515
use Symfony\Component\Yaml\Parser;
1616
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
1717
use Drupal\Component\Serialization\Yaml;
@@ -22,6 +22,7 @@
2222

2323
class EditCommand extends Command
2424
{
25+
2526
/**
2627
* @var ConfigFactory
2728
*/
@@ -40,20 +41,21 @@ class EditCommand extends Command
4041
/**
4142
* EditCommand constructor.
4243
*
43-
* @param ConfigFactory $configFactory
44-
* @param CachedStorage $configStorage
45-
* @param ConfigurationManager $configurationManager
44+
* @param ConfigFactory $configFactory
45+
* @param CachedStorage $configStorage
46+
* @param ConfigurationManager $configurationManager
4647
*/
4748
public function __construct(
4849
ConfigFactory $configFactory,
4950
CachedStorage $configStorage,
5051
ConfigurationManager $configurationManager
5152
) {
52-
$this->configFactory = $configFactory;
53-
$this->configStorage = $configStorage;
53+
$this->configFactory = $configFactory;
54+
$this->configStorage = $configStorage;
5455
$this->configurationManager = $configurationManager;
5556
parent::__construct();
5657
}
58+
5759
/**
5860
* {@inheritdoc}
5961
*/
@@ -80,34 +82,42 @@ protected function configure()
8082
*/
8183
protected function execute(InputInterface $input, OutputInterface $output)
8284
{
83-
$configName = $input->getArgument('config-name');
84-
$editor = $input->getArgument('editor');
85-
$config = $this->configFactory->getEditable($configName);
86-
$configSystem = $this->configFactory->get('system.file');
85+
$configName = $input->getArgument('config-name');
86+
$editor = $input->getArgument('editor');
87+
$config = $this->configFactory->getEditable($configName);
88+
$configSystem = $this->configFactory->get('system.file');
8789
$temporaryDirectory = $configSystem->get('path.temporary') ?: '/tmp';
88-
$configFile = $temporaryDirectory.'/config-edit/'.$configName.'.yml';
89-
$ymlFile = new Parser();
90-
$fileSystem = new Filesystem();
90+
$configFile = $temporaryDirectory.'/config-edit/'.$configName
91+
.'.yml';
92+
$ymlFile = new Parser();
93+
$fileSystem = new Filesystem();
9194

9295
if (!$configName) {
93-
$this->getIo()->error($this->trans('commands.config.edit.messages.no-config'));
96+
$this->getIo()->error(
97+
$this->trans('commands.config.edit.messages.no-config')
98+
);
9499

95100
return 1;
96101
}
97102

98103
try {
99104
$fileSystem->mkdir($temporaryDirectory);
100-
$fileSystem->dumpFile($configFile, $this->getYamlConfig($configName));
105+
$fileSystem->dumpFile(
106+
$configFile,
107+
$this->getYamlConfig($configName)
108+
);
101109
} catch (IOExceptionInterface $e) {
102-
$this->getIo()->error($this->trans('commands.config.edit.messages.no-directory').' '.$e->getPath());
110+
$this->getIo()->error(
111+
$this->trans('commands.config.edit.messages.no-directory').' '
112+
.$e->getPath()
113+
);
103114

104115
return 1;
105116
}
106117
if (!$editor) {
107118
$editor = $this->getEditor();
108119
}
109-
$processBuilder = new ProcessBuilder([$editor, $configFile]);
110-
$process = $processBuilder->getProcess();
120+
$process = new Process([$editor, $configFile]);
111121
$process->setTty('true');
112122
$process->run();
113123

@@ -120,6 +130,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
120130

121131
if (!$process->isSuccessful()) {
122132
$this->getIo()->error($process->getErrorOutput());
133+
123134
return 1;
124135
}
125136

@@ -131,8 +142,10 @@ protected function interact(InputInterface $input, OutputInterface $output)
131142
$configName = $input->getArgument('config-name');
132143
if (!$configName) {
133144
$configNames = $this->configFactory->listAll();
134-
$configName = $this->getIo()->choice(
135-
$this->trans('commands.config.edit.messages.choose-configuration'),
145+
$configName = $this->getIo()->choice(
146+
$this->trans(
147+
'commands.config.edit.messages.choose-configuration'
148+
),
136149
$configNames
137150
);
138151

@@ -148,7 +161,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
148161
protected function getYamlConfig($config_name)
149162
{
150163
if ($this->configStorage->exists($config_name)) {
151-
$configuration = $this->configStorage->read($config_name);
164+
$configuration = $this->configStorage->read($config_name);
152165
$configurationEncoded = Yaml::encode($configuration);
153166
}
154167

@@ -167,13 +180,13 @@ protected function getEditor()
167180
return trim($editor);
168181
}
169182

170-
$processBuilder = new ProcessBuilder(['bash']);
171-
$process = $processBuilder->getProcess();
172-
$process->setCommandLine('echo ${EDITOR:-${VISUAL:-vi}}');
183+
$process = new Process(['bash']);
184+
$process->setCommandLine('echo ${EDITOR:-${VISUAL:-nano}}');
173185
$process->run();
174186
$editor = $process->getOutput();
175187
$process->stop();
176188

177189
return trim($editor);
178190
}
191+
179192
}

src/Command/Database/ClientCommand.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
use Symfony\Component\Console\Input\InputArgument;
1111
use Symfony\Component\Console\Input\InputInterface;
1212
use Symfony\Component\Console\Output\OutputInterface;
13-
use Symfony\Component\Process\ProcessBuilder;
13+
use Symfony\Component\Process\Process;
1414
use Drupal\Console\Core\Command\Command;
1515
use Drupal\Console\Command\Shared\ConnectTrait;
1616

1717
class ClientCommand extends Command
1818
{
19+
1920
use ConnectTrait;
2021

2122
/**
@@ -25,7 +26,9 @@ protected function configure()
2526
{
2627
$this
2728
->setName('database:client')
28-
->setDescription($this->trans('commands.database.client.description'))
29+
->setDescription(
30+
$this->trans('commands.database.client.description')
31+
)
2932
->addArgument(
3033
'database',
3134
InputArgument::OPTIONAL,
@@ -49,23 +52,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
4952
{
5053
$database = $input->getArgument('database');
5154
$learning = $input->getOption('learning');
52-
$target = $input->getArgument('target');
55+
$target = $input->getArgument('target');
5356

5457
$databaseConnection = $this->resolveConnection($database, $target);
55-
$connection = $this->getConnectionString($databaseConnection);
58+
$connection = $this->getConnectionString($databaseConnection);
5659

5760
if ($learning) {
5861
$this->getIo()->commentBlock(
5962
sprintf(
60-
$this->trans('commands.database.client.messages.connection'),
63+
$this->trans(
64+
'commands.database.client.messages.connection'
65+
),
6166
$connection
6267
)
6368
);
6469
}
6570

66-
$processBuilder = new ProcessBuilder([]);
67-
$processBuilder->setArguments(explode(' ', $connection));
68-
$process = $processBuilder->getProcess();
71+
$process = new Process(explode(' ', $connection));
6972
$process->setTty('true');
7073
$process->run();
7174

@@ -75,4 +78,5 @@ protected function execute(InputInterface $input, OutputInterface $output)
7578

7679
return 0;
7780
}
81+
7882
}

src/Command/Database/QueryCommand.php

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
use Symfony\Component\Console\Input\InputInterface;
1717
use Symfony\Component\Console\Input\InputOption;
1818
use Symfony\Component\Console\Output\OutputInterface;
19-
use Symfony\Component\Process\ProcessBuilder;
19+
use Symfony\Component\Process\Process;
2020
use Drupal\Console\Core\Command\Command;
2121
use Drupal\Console\Command\Shared\ConnectTrait;
2222

2323
class QueryCommand extends Command
2424
{
25+
2526
use ConnectTrait;
2627

2728
/**
@@ -31,7 +32,9 @@ protected function configure()
3132
{
3233
$this
3334
->setName('database:query')
34-
->setDescription($this->trans('commands.database.query.description'))
35+
->setDescription(
36+
$this->trans('commands.database.query.description')
37+
)
3538
->addArgument(
3639
'query',
3740
InputArgument::REQUIRED,
@@ -49,14 +52,48 @@ protected function configure()
4952
$this->trans('commands.database.connect.arguments.target'),
5053
'default'
5154
)
52-
->addOption('quick', null, InputOption::VALUE_NONE, $this->trans('commands.database.query.options.quick'))
53-
->addOption('debug', null, InputOption::VALUE_NONE, $this->trans('commands.database.query.options.debug'))
54-
->addOption('html', null, InputOption::VALUE_NONE, $this->trans('commands.database.query.options.html'))
55-
->addOption('xml', null, InputOption::VALUE_NONE, $this->trans('commands.database.query.options.xml'))
56-
->addOption('raw', null, InputOption::VALUE_NONE, $this->trans('commands.database.query.options.raw'))
57-
->addOption('vertical', null, InputOption::VALUE_NONE, $this->trans('commands.database.query.options.vertical'))
58-
->addOption('batch', null, InputOption::VALUE_NONE, $this->trans('commands.database.query.options.batch'))
59-
55+
->addOption(
56+
'quick',
57+
null,
58+
InputOption::VALUE_NONE,
59+
$this->trans('commands.database.query.options.quick')
60+
)
61+
->addOption(
62+
'debug',
63+
null,
64+
InputOption::VALUE_NONE,
65+
$this->trans('commands.database.query.options.debug')
66+
)
67+
->addOption(
68+
'html',
69+
null,
70+
InputOption::VALUE_NONE,
71+
$this->trans('commands.database.query.options.html')
72+
)
73+
->addOption(
74+
'xml',
75+
null,
76+
InputOption::VALUE_NONE,
77+
$this->trans('commands.database.query.options.xml')
78+
)
79+
->addOption(
80+
'raw',
81+
null,
82+
InputOption::VALUE_NONE,
83+
$this->trans('commands.database.query.options.raw')
84+
)
85+
->addOption(
86+
'vertical',
87+
null,
88+
InputOption::VALUE_NONE,
89+
$this->trans('commands.database.query.options.vertical')
90+
)
91+
->addOption(
92+
'batch',
93+
null,
94+
InputOption::VALUE_NONE,
95+
$this->trans('commands.database.query.options.batch')
96+
)
6097
->setHelp($this->trans('commands.database.query.help'))
6198
->setAliases(['dbq']);
6299
}
@@ -66,9 +103,9 @@ protected function configure()
66103
*/
67104
protected function execute(InputInterface $input, OutputInterface $output)
68105
{
69-
$query = $input->getArgument('query');
106+
$query = $input->getArgument('query');
70107
$database = $input->getArgument('database');
71-
$target = $input->getArgument('target');
108+
$target = $input->getArgument('target');
72109
$learning = $input->getOption('learning');
73110

74111
$databaseConnection = $this->resolveConnection($database, $target);
@@ -83,14 +120,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
83120
$databaseConnection['port']
84121
);
85122

86-
$args = explode(' ', $connection);
123+
$args = explode(' ', $connection);
87124
$args[] = sprintf('--execute=%s', $query);
88125

89126
$opts = ['quick', 'debug', 'html', 'xml', 'raw', 'vertical', 'batch'];
90127
array_walk(
91128
$opts, function ($opt) use ($input, &$args) {
92-
if ($input->getOption($opt)) {
93-
switch ($opt) {
129+
if ($input->getOption($opt)) {
130+
switch ($opt) {
94131
case 'quick':
95132
$args[] = '--quick';
96133
break;
@@ -112,9 +149,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
112149
case 'batch':
113150
$args[] = '--batch';
114151
break;
115-
}
116152
}
117153
}
154+
}
118155
);
119156

120157
if ($learning) {
@@ -123,9 +160,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
123160
);
124161
}
125162

126-
$processBuilder = new ProcessBuilder();
127-
$processBuilder->setArguments($args);
128-
$process = $processBuilder->getProcess();
163+
$process = new Process($args);
129164
$process->setTty('true');
130165
$process->run();
131166

@@ -135,4 +170,5 @@ protected function execute(InputInterface $input, OutputInterface $output)
135170

136171
return 0;
137172
}
173+
138174
}

src/Command/Generate/ComposerCommand.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ protected function configure()
7070
InputOption::VALUE_REQUIRED,
7171
$this->trans('commands.common.options.module')
7272
)
73+
->addOption(
74+
'package-path',
75+
null,
76+
InputOption::VALUE_OPTIONAL,
77+
$this->trans('commands.generate.composer.options.package-path')
78+
)
7379
->addOption(
7480
'name',
7581
null,
@@ -377,6 +383,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
377383
}
378384

379385
$module = $input->getOption('module');
386+
$packagePath = $input->getOption('package-path');
380387
$name = $input->getOption('name');
381388
$type = $input->getOption('type');
382389
$description = $input->getOption('description');
@@ -398,6 +405,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
398405

399406
$this->generator->generate([
400407
'machine_name' => $module,
408+
'package_path' => $packagePath,
401409
'name' => $name,
402410
'type' => $type,
403411
'description' => $description,

src/Command/Generate/ModuleCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
244244
->addCommand(
245245
'generate:composer', [
246246
'--module' => $machineName,
247+
'--package-path' => $modulePath,
247248
'--name' => 'drupal/' . $machineName,
248249
'--type' => 'drupal-module',
249250
'--description' => $description,

0 commit comments

Comments
 (0)