Book Image

Drush for Developers - Second Edition

By : Juan Pablo Novillo Requena, Juan P Novillo Requena
Book Image

Drush for Developers - Second Edition

By: Juan Pablo Novillo Requena, Juan P Novillo Requena

Overview of this book

Table of Contents (13 chapters)
Drush for Developers Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
2
Keeping Database Configuration and Code Together
Index

Validating input


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.

Validating an argument

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...