Skip to content

Commit

Permalink
Update Druplicon hook and ExampleCommandFile to new hook APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-1-anderson committed Sep 30, 2016
1 parent caa675b commit 377f087
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
"symfony/yaml": "~2.3|~3.0",
"symfony/var-dumper": "~2.7|~3.0",
"league/container": "~2",
"consolidation/robo": "dev-container-config",
"consolidation/annotated-command": "~2",
"consolidation/robo": "dev-hook-apis",
"consolidation/annotated-command": "dev-master",
"consolidation/output-formatters": "~2",
"symfony/console": "2.7.*",
"symfony/event-dispatcher": "2.7.*",
Expand Down
29 changes: 15 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions lib/Drush/CommandFiles/ExampleCommandFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Consolidation\AnnotatedCommand\AnnotationData;
use Consolidation\OutputFormatters\StructuredData\RowsOfFields;

use Consolidation\AnnotatedCommand\CommandData;

class ExampleCommandFile
{
/**
Expand Down Expand Up @@ -46,9 +48,9 @@ public function exampleTable($options = ['format' => 'table', 'fields' => ''])
* @option $french Add a row with French numbers.
* @usage example:formatters --french
*/
public function alterFormatters($result, array $args, AnnotationData $annotationData)
public function alterFormatters($result, CommandData $commandData)
{
if ($args['options']['french']) {
if ($commandData->input()->getOption('french')) {
$result['fr'] = [ 'first' => 'Un', 'second' => 'Deux', 'third' => 'Trois' ];
}

Expand Down
22 changes: 20 additions & 2 deletions lib/Drush/CommandFiles/core/DrupliconCommands.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
<?php
namespace Drush\CommandFiles\core;

use Consolidation\AnnotatedCommand\CommandData;

class DrupliconCommands {
protected $printed = false;

/**
* Print druplicon as post-command output.
*
* @hook post-command *
* @option $druplicon Shows the druplicon as glorious ASCII art.
*/
public function druplicon($result, $argsAndOptions, $annotationData) {
if ($argsAndOptions['options']['druplicon']) {
public function druplicon($result, CommandData $commandData) {
// If one command does a drush_invoke to another command,
// then this hook will be called multiple times. Only print
// once. (n.b. If drush_invoke_process passes along the
// --druplicon option, then we will still get mulitple output)
if ($this->printed) {
return;
}
$this->printed = true;
$annotationData = $commandData->annotationData();
$commandName = $annotationData['command'];
// For some reason, Drush help uses drush_invoke_process to call helpsingle
if ($commandName == 'helpsingle') {
return;
}
drush_log(dt('Displaying Druplicon for "!command" command.', array('!command' => $commandName)));
if ($commandData->input()->getOption('druplicon')) {
$misc_dir = DRUSH_BASE_PATH . '/misc';
if (drush_get_context('DRUSH_NOCOLOR')) {
$content = file_get_contents($misc_dir . '/druplicon-no_color.txt');
Expand Down

0 comments on commit 377f087

Please sign in to comment.