Skip to content

Commit 24033d3

Browse files
authored
Use constants for command names (#5803)
* Use constants for command names * Use command constants when calling other commands.
1 parent dbc97d7 commit 24033d3

File tree

9 files changed

+19
-14
lines changed

9 files changed

+19
-14
lines changed

src/Commands/config/ConfigCommands.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public function edit($config_name, $options = []): void
242242
if (!$options['bg']) {
243243
$redispatch_options = Drush::redispatchOptions() + ['strict' => 0, 'partial' => true, 'source' => $temp_dir];
244244
$self = $this->siteAliasManager()->getSelf();
245-
$process = $this->processManager()->drush($self, 'config-import', [], $redispatch_options);
245+
$process = $this->processManager()->drush($self, ConfigImportCommands::IMPORT, [], $redispatch_options);
246246
$process->mustRun($process->showRealtime());
247247
}
248248
}

src/Commands/config/ConfigPullCommands.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Consolidation\AnnotatedCommand\Hooks\HookManager;
99
use Drush\Attributes as CLI;
1010
use Drush\Commands\core\DocsCommands;
11+
use Drush\Commands\core\RsyncCommands;
1112
use Drush\Commands\DrushCommands;
1213
use Drush\Drush;
1314
use Consolidation\SiteAlias\HostPath;
@@ -45,7 +46,7 @@ public function pull(string $source, string $destination, array $options = ['saf
4546
'format' => 'string',
4647
];
4748
$this->logger()->notice(dt('Starting to export configuration on :destination.', [':destination' => $destination]));
48-
$process = $this->processManager()->drush($sourceRecord, 'config-export', [], $export_options + $global_options);
49+
$process = $this->processManager()->drush($sourceRecord, ConfigExportCommands::EXPORT, [], $export_options + $global_options);
4950
$process->mustRun();
5051

5152
if ($this->getConfig()->simulate()) {
@@ -77,7 +78,7 @@ public function pull(string $source, string $destination, array $options = ['saf
7778
'delete' => true,
7879
'exclude' => '.htaccess',
7980
];
80-
$process = $this->processManager()->drush($runner, 'core-rsync', $args, ['yes' => true, 'debug' => true], $options_double_dash);
81+
$process = $this->processManager()->drush($runner, RsyncCommands::RSYNC, $args, ['yes' => true, 'debug' => true], $options_double_dash);
8182
$process->mustRun();
8283
return new PropertyList(['path' => $destinationHostPath->getOriginal()]);
8384
}

src/Commands/core/BrowseCommands.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ final class BrowseCommands extends DrushCommands implements SiteAliasManagerAwar
1818
use ExecTrait;
1919
use SiteAliasManagerAwareTrait;
2020

21+
const BROWSE = 'browse';
22+
2123
/**
2224
* Display a link to a given path or open link in a browser.
2325
*/
24-
#[CLI\Command(name: 'browse')]
26+
#[CLI\Command(name: self::BROWSE)]
2527
#[CLI\Argument(name: 'path', description: 'Path to open. If omitted, the site front page will be opened.')]
2628
#[CLI\Option(name: 'browser', description: 'Open the URL in the default browser. Use --no-browser to avoid opening a browser.')]
2729
#[CLI\Option(name: 'redirect-port', description: 'The port that the web server is redirected to (e.g. when running within a Vagrant environment).')]
@@ -35,7 +37,7 @@ public function browse($path = '', array $options = ['browser' => true, 'redirec
3537
// Redispatch if called against a remote-host so a browser is started on the
3638
// the *local* machine.
3739
if ($this->processManager()->hasTransport($aliasRecord)) {
38-
$process = $this->processManager()->drush($aliasRecord, 'browse', [$path], Drush::redispatchOptions());
40+
$process = $this->processManager()->drush($aliasRecord, self::BROWSE, [$path], Drush::redispatchOptions());
3941
$process->mustRun();
4042
$link = $process->getOutput();
4143
} else {

src/Commands/core/CacheCommands.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ protected function setPrepareData($data, $options)
199199
if (is_object($data) && $data->data) {
200200
$data = $data->data;
201201
} elseif (is_array($data) && isset($data['data'])) {
202-
// But $data returned from `drush cache-get --format=json` will be an array.
202+
// But $data returned from `drush cache:get --format=json` will be an array.
203203
$data = $data['data'];
204204
} else {
205205
// If $data is neither object nor array and cache-get was specified, then

src/Commands/core/CliCommands.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ protected function getDrushCommands(): array
132132
$ignored_commands = [
133133
'help',
134134
self::PHP,
135-
'core:cli',
135+
CliCommands::PHP,
136136
'php',
137-
'php:eval',
137+
PhpCommands::EVAL,
138138
'eval',
139139
'ev',
140-
'php:script',
140+
PhpCommands::SCRIPT,
141141
'scr',
142142
];
143143
$php_keywords = $this->getPhpKeywords();

src/Commands/core/CoreCommands.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ final class CoreCommands extends DrushCommands implements SiteAliasManagerAwareI
1818
use SiteAliasManagerAwareTrait;
1919

2020
const VERSION = 'version';
21+
const GLOBAL_OPTIONS = 'core:global-options';
2122

2223
/**
2324
* All global options.
2425
*/
25-
#[CLI\Command(name: 'core:global-options', aliases: ['core-global-options'])]
26+
#[CLI\Command(name: self::GLOBAL_OPTIONS, aliases: ['core-global-options'])]
2627
#[CLI\Help(hidden: true)]
2728
#[CLI\Topics(isTopic: true)]
2829
#[CLI\FieldLabels(labels: ['name' => 'Name', 'description' => 'Description'])]

src/Commands/core/EditCommands.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ final class EditCommands extends DrushCommands implements SiteAliasManagerAwareI
3232
#[CLI\Usage(name: 'drush core:edit sett', description: 'Edit settings.php for the current Drupal site.')]
3333
#[CLI\Usage(name: 'drush core:edit --choice=2', description: 'Edit the second file in the choice list.')]
3434
#[CLI\Bootstrap(level: DrupalBootLevels::MAX)]
35-
#[CLI\HookSelector(name: 'optionset_get_editor')]
35+
#[CLI\OptionsetGetEditor]
3636
public function edit($filter = null, array $options = []): void
3737
{
3838
$all = $this->load();

src/Commands/core/RoleCommands.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function roleAddPerm($machine_name, $permissions): void
7878
$perms = StringUtils::csvToArray($permissions);
7979
user_role_grant_permissions($machine_name, $perms);
8080
$this->logger()->success(dt('Added "!permissions" to "!role"', ['!permissions' => $permissions, '!role' => $machine_name]));
81-
$this->processManager()->drush($this->siteAliasManager()->getSelf(), 'cache:rebuild');
81+
$this->processManager()->drush($this->siteAliasManager()->getSelf(), CacheRebuildCommands::REBUILD);
8282
}
8383

8484
/**
@@ -97,7 +97,7 @@ public function roleRemovePerm($machine_name, $permissions): void
9797
$perms = StringUtils::csvToArray($permissions);
9898
user_role_revoke_permissions($machine_name, $perms);
9999
$this->logger()->success(dt('Removed "!permissions" to "!role"', ['!permissions' => $permissions, '!role' => $machine_name]));
100-
$this->processManager()->drush($this->siteAliasManager()->getSelf(), 'cache:rebuild');
100+
$this->processManager()->drush($this->siteAliasManager()->getSelf(), CacheRebuildCommands::REBUILD);
101101
}
102102

103103
/**

src/Commands/sql/SqlSyncCommands.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Consolidation\AnnotatedCommand\CommandData;
88
use Consolidation\AnnotatedCommand\Hooks\HookManager;
99
use Drush\Attributes as CLI;
10+
use Drush\Commands\core\CoreCommands;
1011
use Drush\Commands\core\DocsCommands;
1112
use Drush\Commands\core\RsyncCommands;
1213
use Drush\Commands\core\StatusCommands;
@@ -114,7 +115,7 @@ public function databaseName(SiteAlias $record): string
114115
return 'simulated_db';
115116
}
116117

117-
$process = $this->processManager()->drush($record, 'core-status', [], ['fields' => 'db-name', 'format' => 'json']);
118+
$process = $this->processManager()->drush($record, StatusCommands::STATUS, [], ['fields' => 'db-name', 'format' => 'json']);
118119
$process->setSimulated(false);
119120
$process->mustRun();
120121
$data = $process->getOutputAsJson();

0 commit comments

Comments
 (0)