Currently on drush v12.5.2.0 and I am using drush sql:sync
to sync my local with the remote db. I want to ensure I do not enter @prod for the target.
I realized I could use drush policy to validate [https://www.drush.org/12.x/examples/PolicyCommands.php/][1]
I have the below file in my project/drush/Commands
<?php
namespace Drush\Commands;
use Consolidation\AnnotatedCommand\CommandData;
use Drush\Commands\DrushCommands;
class PolicyCommands extends DrushCommands {
/**
* Prevent catastrophic braino.
*
* @throws \Exception
*/
#[CLI\Hook(type: HookManager::ARGUMENT_VALIDATOR, target: SqlSyncCommands::SYNC)]
public function sqlSyncValidate(CommandData $commandData) {
if ($commandData->input()->getArgument('target') == '@prod') {
throw new \Exception(dt('Per !file, you may never overwrite the production database.', ['!file' => __FILE__]));
}
}
}
I cleared the drush cache using drush cc drush
as well.
#Load this commandfile using the --include option - e.g. `drush --include=/path/to/drush/examples
.
I ran drush --include=~/project/drush/Commands
but still no luck.
Kind of a newbie so am I missing something? If I still give drush sql:sync @self @prod
it does not throw any Exception..
Drush\Commands\PolicyCommands
namespace rather thanDrush\Commands
? I don't know if that's the only problem here, but it looks wrong. In addition have you execute Drush in debug/verbose mode for more information?sql:sync
to remote aliases.Drush\Commands
at first but still couldn't make it work. I have edited the question's code.drush.yml
underdrush:paths:include