function drush_role_list

8.0.x role.drush.inc drush_role_list($rid = '')
6.x role.drush.inc drush_role_list($rid = '')
7.x role.drush.inc drush_role_list($rid = '')
master role.drush.inc drush_role_list($rid = '')

Displays a list of roles

File

commands/core/role.drush.inc, line 201

Code

function drush_role_list($rid = '') {
  $result = array();
  if (empty($rid)) {
    drush_hide_output_fields(array('perm'));
    // get options passed
    $perm = drush_get_option('filter');
    $roles = array();

    // get all roles - if $perm is empty user_roles retrieves all roles
    $roles = user_roles(FALSE, $perm);
    if (empty($roles)) {
      return drush_set_error('DRUSH_NO_ROLES', dt("No roles found."));
    }
    foreach ($roles as $rid => $role_name) {
      $result[$role_name] = array(
        'rid' => $rid,
        'role' => $role_name,
      );
    }
  }
  else {
    drush_hide_output_fields(array('rid', 'role'));
    $role = drush_role_get_class($rid);
    if (!$role) {
      return FALSE;
    }
    $perms = $role->getPerms();
    foreach ($perms as $permission) {
      $result[$permission] = array(
        'perm' => $permission,
      );
    }
  }
  return $result;
}