Skip to content

Commit

Permalink
Use constants for command names (#5803)
Browse files Browse the repository at this point in the history
* Use constants for command names

* Use command constants when calling other commands.
  • Loading branch information
weitzman authored Nov 5, 2023
1 parent dbc97d7 commit 24033d3
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Commands/config/ConfigCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public function edit($config_name, $options = []): void
if (!$options['bg']) {
$redispatch_options = Drush::redispatchOptions() + ['strict' => 0, 'partial' => true, 'source' => $temp_dir];
$self = $this->siteAliasManager()->getSelf();
$process = $this->processManager()->drush($self, 'config-import', [], $redispatch_options);
$process = $this->processManager()->drush($self, ConfigImportCommands::IMPORT, [], $redispatch_options);
$process->mustRun($process->showRealtime());
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/Commands/config/ConfigPullCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Consolidation\AnnotatedCommand\Hooks\HookManager;
use Drush\Attributes as CLI;
use Drush\Commands\core\DocsCommands;
use Drush\Commands\core\RsyncCommands;
use Drush\Commands\DrushCommands;
use Drush\Drush;
use Consolidation\SiteAlias\HostPath;
Expand Down Expand Up @@ -45,7 +46,7 @@ public function pull(string $source, string $destination, array $options = ['saf
'format' => 'string',
];
$this->logger()->notice(dt('Starting to export configuration on :destination.', [':destination' => $destination]));
$process = $this->processManager()->drush($sourceRecord, 'config-export', [], $export_options + $global_options);
$process = $this->processManager()->drush($sourceRecord, ConfigExportCommands::EXPORT, [], $export_options + $global_options);
$process->mustRun();

if ($this->getConfig()->simulate()) {
Expand Down Expand Up @@ -77,7 +78,7 @@ public function pull(string $source, string $destination, array $options = ['saf
'delete' => true,
'exclude' => '.htaccess',
];
$process = $this->processManager()->drush($runner, 'core-rsync', $args, ['yes' => true, 'debug' => true], $options_double_dash);
$process = $this->processManager()->drush($runner, RsyncCommands::RSYNC, $args, ['yes' => true, 'debug' => true], $options_double_dash);
$process->mustRun();
return new PropertyList(['path' => $destinationHostPath->getOriginal()]);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Commands/core/BrowseCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ final class BrowseCommands extends DrushCommands implements SiteAliasManagerAwar
use ExecTrait;
use SiteAliasManagerAwareTrait;

const BROWSE = 'browse';

/**
* Display a link to a given path or open link in a browser.
*/
#[CLI\Command(name: 'browse')]
#[CLI\Command(name: self::BROWSE)]
#[CLI\Argument(name: 'path', description: 'Path to open. If omitted, the site front page will be opened.')]
#[CLI\Option(name: 'browser', description: 'Open the URL in the default browser. Use --no-browser to avoid opening a browser.')]
#[CLI\Option(name: 'redirect-port', description: 'The port that the web server is redirected to (e.g. when running within a Vagrant environment).')]
Expand All @@ -35,7 +37,7 @@ public function browse($path = '', array $options = ['browser' => true, 'redirec
// Redispatch if called against a remote-host so a browser is started on the
// the *local* machine.
if ($this->processManager()->hasTransport($aliasRecord)) {
$process = $this->processManager()->drush($aliasRecord, 'browse', [$path], Drush::redispatchOptions());
$process = $this->processManager()->drush($aliasRecord, self::BROWSE, [$path], Drush::redispatchOptions());
$process->mustRun();
$link = $process->getOutput();
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/core/CacheCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ protected function setPrepareData($data, $options)
if (is_object($data) && $data->data) {
$data = $data->data;
} elseif (is_array($data) && isset($data['data'])) {
// But $data returned from `drush cache-get --format=json` will be an array.
// But $data returned from `drush cache:get --format=json` will be an array.
$data = $data['data'];
} else {
// If $data is neither object nor array and cache-get was specified, then
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/core/CliCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ protected function getDrushCommands(): array
$ignored_commands = [
'help',
self::PHP,
'core:cli',
CliCommands::PHP,
'php',
'php:eval',
PhpCommands::EVAL,
'eval',
'ev',
'php:script',
PhpCommands::SCRIPT,
'scr',
];
$php_keywords = $this->getPhpKeywords();
Expand Down
3 changes: 2 additions & 1 deletion src/Commands/core/CoreCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ final class CoreCommands extends DrushCommands implements SiteAliasManagerAwareI
use SiteAliasManagerAwareTrait;

const VERSION = 'version';
const GLOBAL_OPTIONS = 'core:global-options';

/**
* All global options.
*/
#[CLI\Command(name: 'core:global-options', aliases: ['core-global-options'])]
#[CLI\Command(name: self::GLOBAL_OPTIONS, aliases: ['core-global-options'])]
#[CLI\Help(hidden: true)]
#[CLI\Topics(isTopic: true)]
#[CLI\FieldLabels(labels: ['name' => 'Name', 'description' => 'Description'])]
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/core/EditCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class EditCommands extends DrushCommands implements SiteAliasManagerAwareI
#[CLI\Usage(name: 'drush core:edit sett', description: 'Edit settings.php for the current Drupal site.')]
#[CLI\Usage(name: 'drush core:edit --choice=2', description: 'Edit the second file in the choice list.')]
#[CLI\Bootstrap(level: DrupalBootLevels::MAX)]
#[CLI\HookSelector(name: 'optionset_get_editor')]
#[CLI\OptionsetGetEditor]
public function edit($filter = null, array $options = []): void
{
$all = $this->load();
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/core/RoleCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function roleAddPerm($machine_name, $permissions): void
$perms = StringUtils::csvToArray($permissions);
user_role_grant_permissions($machine_name, $perms);
$this->logger()->success(dt('Added "!permissions" to "!role"', ['!permissions' => $permissions, '!role' => $machine_name]));
$this->processManager()->drush($this->siteAliasManager()->getSelf(), 'cache:rebuild');
$this->processManager()->drush($this->siteAliasManager()->getSelf(), CacheRebuildCommands::REBUILD);
}

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

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Commands/sql/SqlSyncCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Consolidation\AnnotatedCommand\CommandData;
use Consolidation\AnnotatedCommand\Hooks\HookManager;
use Drush\Attributes as CLI;
use Drush\Commands\core\CoreCommands;
use Drush\Commands\core\DocsCommands;
use Drush\Commands\core\RsyncCommands;
use Drush\Commands\core\StatusCommands;
Expand Down Expand Up @@ -114,7 +115,7 @@ public function databaseName(SiteAlias $record): string
return 'simulated_db';
}

$process = $this->processManager()->drush($record, 'core-status', [], ['fields' => 'db-name', 'format' => 'json']);
$process = $this->processManager()->drush($record, StatusCommands::STATUS, [], ['fields' => 'db-name', 'format' => 'json']);
$process->setSimulated(false);
$process->mustRun();
$data = $process->getOutputAsJson();
Expand Down

0 comments on commit 24033d3

Please sign in to comment.