You are here

function patterns_drush_command in Patterns 7

Same name and namespace in other branches
  1. 6.2 patterns.drush.inc \patterns_drush_command()
  2. 7.2 patterns.drush.inc \patterns_drush_command()

Implements hook_drush_command().

File

./patterns.drush.inc, line 46
Drush Patterns module commands

Code

function patterns_drush_command() {
  $dependencies = array(
    'patterns',
    'patterns_components',
    'patterns_phpparser',
    'patterns_yamlparser',
    'patterns_xmlparser',
    'token',
  );
  $deps_export = $dependencies;
  array_push($deps_export, 'patterns_export');

  // TODO: do we need the form-helper command ?

  /*
    $items['patterns-form-helper'] = array(
      'description' => 'Enable/disable patterns form helper',
      'arguments' => array(
        'action' => "Valid values: enable, disable.",
      )
    );
  */

  // configuration / information
  $items['patterns'] = array(
    'callback' => 'drush_patterns',
    'description' => "List all available patterns.",
  );
  $items['patterns-paths'] = array(
    'description' => "List all paths where patterns will be looked for",
    'drupal dependencies' => array(
      'patterns',
    ),
  );
  $items['patterns-components'] = array(
    'description' => "List all the available patterns components",
    'drupal dependencies' => array(
      'patterns',
    ),
  );
  $items['patterns-info'] = array(
    'callback' => 'drush_patterns_info',
    'description' => "Show all info on a given pattern.",
    'arguments' => array(
      'id' => "The id or the name of the pattern as stored in the database.",
    ),
  );
  $items['patterns-allow-publish'] = array(
    'description' => 'Enable/disable patterns publishing',
    'arguments' => array(
      'action' => "Valid values: enable, disable.",
    ),
  );
  $items['patterns-publish'] = array(
    'description' => "Publish a pattern.",
    'arguments' => array(
      'id' => "The id or the name of the pattern to publish.",
    ),
    'drupal dependencies' => array(
      'patterns',
    ),
  );
  $items['patterns-unpublish'] = array(
    'description' => "Unpublish a pattern.",
    'arguments' => array(
      'id' => "The id or the name of the pattern to unpublish.",
    ),
    'drupal dependencies' => array(
      'patterns',
    ),
  );

  // run / quickrun
  $items['patterns-quickrun'] = array(
    'callback' => 'drush_patterns_quickrun',
    'description' => 'Load a pattern file and executes it without saving it into the database',
    'examples' => array(
      'drush patterns-quickrun myPattern.yaml' => 'Read myPattern.yaml,  parses it using the XMLParser, and runs it in php mode',
      'drush patterns-quickrun myPattern yaml batch' => 'Read myPattern,  parses it using the YAMLParser, and runs it in batch mode',
    ),
    'arguments' => array(
      'file_name' => 'The path to the a pattern file',
      'format' => 'Optional. The format of the pattern. If not specified, it will be determined by the file extension.',
      'mode' => 'Optional. Execute via "batch" or "php". Defaults "php"',
    ),
    'drupal dependencies' => $dependencies,
    'core' => array(
      '7',
    ),
  );
  $items['patterns-run'] = array(
    'callback' => 'drush_patterns_run',
    'description' => 'Import and enable the specified pattern file',
    'examples' => array(
      'drush patterns-run path/to/patterns/file.xml' => 'Parses file.xml using the XMLParser, imports it into the database and runs it',
      'drush patterns-run path/to/pattern/file yaml batch' => 'Parses file using the YAMLParser, imports it into the database and runs it in batch mode',
      'drush patterns-run 2' => 'Runs the pattern stored in the database with id 2',
      'drush patterns-run pattern_in_db.yaml' => 'Runs the pattern stored in the database with the name pattern_in_db.yaml',
    ),
    'arguments' => array(
      'pattern' => 'The path to the a pattern file, the pattern id or the pattern name',
      'format' => 'Optional. The format of the pattern. If not specified, it will be determined by the file extension.',
      'mode' => 'Optional. Execute via "batch" or "php". Defaults "php"',
    ),
    'drupal dependencies' => $dependencies,
    'core' => array(
      '7',
    ),
  );
  $items['patterns-import'] = array(
    'callback' => 'drush_patterns_import_file',
    'description' => 'Import a pattern local file into the database.',
    'examples' => array(
      'drush patterns-import path/to/patterns/file.xml' => 'Parses file.xml using the XMLParser, and saves the results into the database.',
      'drush patterns-import path/to/pattern/file' => 'Import the specified pattern file and give it a machine readable name',
    ),
    'arguments' => array(
      'file' => 'The path to a pattern file',
      'format' => 'Optional. A valid pattern format, e.g. xml or yaml. If not specified, it will be determined by the file extension.',
    ),
    'drupal dependencies' => $dependencies,
    'core' => array(
      '7',
    ),
  );
  $items['patterns-import-remote'] = array(
    'callback' => 'drush_patterns_import_file_remote',
    'description' => 'Import a remote pattern file into the database.',
    'examples' => array(
      'drush patterns-import-remote http://myserver.org/mypattern.yaml' => 'Opens the remote location, parses mypattern.yaml using the YAMLParser, and saves the results into the database.',
      'drush patterns-import-remote http://myserver.org/mypattern yaml' => 'Opens the remote location, parses mypattern using the YAMLParser, and saves the results into the database.',
    ),
    'arguments' => array(
      'uri' => 'The uri to a pattern file',
      'format' => 'Optional. A valid pattern format, e.g. xml or yaml. If not specified, it will be determined by the file extension.',
    ),
    'drupal dependencies' => $dependencies,
    'core' => array(
      '7',
    ),
  );
  $items['patterns-export'] = array(
    'description' => 'Export data from all or a selection of patterns components to a file, a zip file, or saves it into the database.',
    'examples' => array(
      'drush patterns-export file path/to/patterns/file.yaml' => 'Exports from *all* available components to the specified file. The file is *not* imported in the database.',
      'drush patterns-export db exported.xml taxonomy' => 'Exports from all tags of the component "taxonomy" and saves the results in the database under the machine_name of exported.xml.',
      'drush patterns-export zip path/to/exported.zip yaml taxonomy.term' => 'Exports from tag "term" of the component "taxonomy" and saves the results in the zip archive exported.zip containing patterns in YAML format.',
      'drush patterns-export file path/to/exported.yaml taxonomy.term.all color block.block' => 'Exports from export_function "all" in tag "term" of the component "taxonomy", from all tags of the component "color", and from tag "block" of component "block". Results are saved to file exported.yaml.',
    ),
    'arguments' => array(
      'action' => 'The export action: export to a file, to a zip archive, or import the result of the export into the database',
      'file_name' => 'The path to a pattern file',
      'format' => 'Optional. To use only in combination with the export to zip action. A valid pattern format, e.g. xml or yaml. If not specified, it will be determined by the file extension.',
      'exports' => 'Optional. A combination of components, tags, and export functions, that determine the content of the exported file',
    ),
    'drupal dependencies' => $deps_export,
    'core' => array(
      '7',
    ),
  );
  return $items;
}