function _drush_verify_cli_options

8.0.x _drush_verify_cli_options($command)
6.x _drush_verify_cli_options($command)
7.x _drush_verify_cli_options($command)
5.x _drush_verify_cli_options($command)
master _drush_verify_cli_options($command)

Fail with an error if the user specified options on the command line that are not documented in the current command record. Also verify that required options are present.

Related topics

1 call to _drush_verify_cli_options()
drush_dispatch in includes/
Given a command record, dispatch it as if it were the original command. Executes in the currently bootstrapped site using the current option contexts. Note that drush_dispatch will not bootstrap any further than the current command has already…


includes/, line 534
The drush command engine.


function _drush_verify_cli_options($command) {
  // Start out with just the options in the current command record.
  $options = _drush_get_command_options($command);
  // Skip all tests if the command is marked to allow anything.
  // Also skip backend commands, which may have options on the commandline
  // that were inherited from the calling command.
  if (($command['allow-additional-options'] === TRUE)) {
    return TRUE;
  // If 'allow-additional-options' contains a list of command names,
  // then union together all of the options from all of the commands.
  if (is_array($command['allow-additional-options'])) {
    $implemented = drush_get_commands();
    foreach ($command['allow-additional-options'] as $subcommand_name) {
      if (array_key_exists($subcommand_name, $implemented)) {
        $options = array_merge($options, _drush_get_command_options($implemented[$subcommand_name]));
  // Also add in global options
  $options = array_merge($options, drush_get_global_options());

  // Add a placeholder option so that backend requests originating from prior versions of Drush are valid.
  $options += array('invoke' => '');

  // Now we will figure out which options in the cli context
  // are not represented in our options list.
  $cli_options = array_keys(drush_get_context('cli'));
  $allowed_options = _drush_flatten_options($options);
  $allowed_options = drush_append_negation_options($allowed_options);
  $disallowed_options = array_diff($cli_options, $allowed_options);
  if (!empty($disallowed_options)) {
    $unknown = count($disallowed_options) > 1 ? dt('Unknown options') : dt('Unknown option');
    if (drush_get_option('strict', TRUE)) {
      $msg = dt("@unknown: --@options.  See `drush help @command` for available options. To suppress this error, add the option --strict=0.", array('@unknown' => $unknown, '@options' => implode(', --', $disallowed_options), '@command' => $command['command']));
      return drush_set_error('DRUSH_UNKNOWN_OPTION', $msg);

  // Next check to see if all required options were specified.
  $missing_required_options = array();
  foreach ($command['options'] as $option_name => $option) {
    if (is_array($option) && !empty($option['required']) && drush_get_option($option_name, NULL) === NULL) {
      $missing_required_options[] = $option_name;
  if (!empty($missing_required_options)) {
    $missing = count($missing_required_options) > 1 ? dt('Missing required options') : dt('Missing required option');
    return drush_set_error(dt("@missing: --@options.  See `drush help @command` for information on usage.", array('@missing' => $missing, '@options' => implode(', --', $missing_required_options), '@command' => $command['command'])));
  return TRUE;