Drush can validate input arguments before handing them over to the command's callback. In this section, we will see how to process arguments and options in order to make sure that the command's callback (the function that actually does the processing of a command) receives the right input data.
By default, Drush won't require any input arguments to execute a command, not even when you define them in the command callback. We can see this in the following example, which defines a command that expects one argument named $argument_1
. We have placed this file at sites/all/drush/testcommand.drush.inc
in our sample Drupal project:
<?php
/**
* @file
* Sample Drush command to test arguments.
*/
/**
* Implements hook_drush_command().
*/
function testcommand_drush_command() {
$items = array();
$items['testcommand'] = array(
'description' => "Tests Drush command arguments",
'arguments' => array(
'argument_1' => 'This is a sample...