Skip to content

Instantly share code, notes, and snippets.

@politsin
Created June 15, 2017 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save politsin/e50f11c0aa2a5006a26bf62506442060 to your computer and use it in GitHub Desktop.
Save politsin/e50f11c0aa2a5006a26bf62506442060 to your computer and use it in GitHub Desktop.
<?php
/**
* Implements drush_hook_COMMAND_validate().
*
* https://github.com/drush-ops/drush/blob/8.x/examples/policy.drush.inc
* Encourage folks to use `composer` instead of Drush pm commands
*/
function drush_policy_pm_updatecode_validate() {
return _deny_message();
}
function drush_policy_pm_update_validate() {
return _deny_message();
}
function drush_policy_pm_download_validate() {
$module = array_shift(pm_parse_arguments(func_get_args()));
return _deny_message($module);
}
function _deny_message($module = 'references') {
if (!drush_get_option('pm-force')) {
$msg = "Drush dl forbidden! Use Composer: drush up = `composer update` & drush dl $module = `composer require drupal/$module`. Or be bad and use --pm-force";
return drush_set_error('POLICY_PM_DENY', dt($msg));
}
}
/**
* Implements hook_drush_help_alter().
*/
function policy_drush_help_alter(&$command) {
if (in_array($command['command'], ['pm-updatecode', 'pm-update', 'pm-download'])) {
$command['options']['pm-force'] = 'Override site policy and allow Drush codebase management (pm-* commands)';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment