-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #3164: Introduce artwork:show command, et. al. #3178
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
<?php | ||
namespace Drush\Commands; | ||
|
||
use Consolidation\AnnotatedCommand\AnnotationData; | ||
use Consolidation\AnnotatedCommand\CommandData; | ||
use Consolidation\AnnotatedCommand\Events\CustomEventAwareInterface; | ||
use Consolidation\AnnotatedCommand\Events\CustomEventAwareTrait; | ||
use Consolidation\OutputFormatters\StructuredData\RowsOfFields; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
use Drush\Style\DrushStyle; | ||
use Drush\Utils\StringUtils; | ||
|
||
/** | ||
* Run these commands using the --include option - e.g. `drush --include=/path/to/drush/examples art sandwich` | ||
* | ||
* For an example of a Drupal module implementing commands, see | ||
* - http://cgit.drupalcode.org/devel/tree/devel_generate/src/Commands | ||
* - http://cgit.drupalcode.org/devel/tree/devel_generate/drush.services.yml | ||
* | ||
* This file is a good example of the first of those bullets (a commandfile) but | ||
* since it isn't part of a module, it does not implement drush.services.yml. | ||
*/ | ||
|
||
class ArtCommands extends DrushCommands implements CustomEventAwareInterface | ||
{ | ||
use CustomEventAwareTrait; | ||
|
||
/** @var string[] */ | ||
protected $arts; | ||
|
||
/** | ||
* Show a fabulous picture. | ||
* | ||
* @command artwork:show | ||
* @aliases arts | ||
* @param $art The name of the art to display | ||
* @usage drush art sandwich | ||
* Show a marvelous picture of a sandwich with pickles. | ||
*/ | ||
public function art($art = '') | ||
{ | ||
$data = $this->getArt(); | ||
$name = $data[$art]['name']; | ||
$description = $data[$art]['description']; | ||
$path = $data[$art]['path']; | ||
$msg = dt('Okay. Here is {art}: {description}', | ||
['art' => $name, 'description' => $description] | ||
); | ||
$this->output()->writeln("\n" . $msg . "\n"); | ||
$this->printFile($path); | ||
} | ||
|
||
/** | ||
* Show a table of information about available art. | ||
* | ||
* @command artwork:list | ||
* @aliases artls | ||
* @field-labels | ||
* name: Name | ||
* description: Description | ||
* path: Path | ||
* @default-fields name,description | ||
* | ||
* @return \Consolidation\OutputFormatters\StructuredData\RowsOfFields | ||
*/ | ||
public function listArt($options = ['format' => 'table']) | ||
{ | ||
$data = $this->getArt(); | ||
return new RowsOfFields($data); | ||
} | ||
|
||
/** | ||
* Commandfiles may also add topics. These will appear in | ||
* the list of topics when `drush topic` is executed. | ||
* To view the topic below, run `drush --include=/full/path/to/examples topic` | ||
*/ | ||
|
||
/** | ||
* Ruminations on the true meaning and philosophy of sandwiches. | ||
* | ||
* @command artwork:explain | ||
* @hidden | ||
* @topic | ||
*/ | ||
public function ruminate() | ||
{ | ||
self::printFile(__DIR__ . '/art-topic.md'); | ||
} | ||
|
||
/** | ||
* Return the available built-in art. Any Drush commandfile may provide | ||
* more art by implementing a 'drush-art' on-event hook. This on-event | ||
* hook is defined in the 'findArt' method beolw. | ||
* | ||
* @hook on-event drush-art | ||
*/ | ||
public function builtInArt() | ||
{ | ||
return [ | ||
'drush' => [ | ||
'name' => 'Drush', | ||
'description' => 'The Drush logo.', | ||
'path' => __DIR__ . '/art/drush-nocolor.txt', | ||
], | ||
'sandwich' => [ | ||
'name' => 'Sandwich', | ||
'description' => 'A tasty meal with bread often consumed at lunchtime.', | ||
'path' => __DIR__ . '/art/sandwich-nocolor.txt', | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @hook interact artwork:show | ||
*/ | ||
public function interact(InputInterface $input, OutputInterface $output, AnnotationData $annotationData) | ||
{ | ||
$io = new DrushStyle($input, $output); | ||
|
||
// If the user did not specify any artwork, then prompt for one. | ||
$art = $input->getArgument('art'); | ||
if (empty($art)) { | ||
$data = $this->getArt(); | ||
$selections = $this->convertArtListToKeyValue($data); | ||
$selection = $io->choice('Select art to display', $selections); | ||
$input->setArgument('art', $selection); | ||
} | ||
} | ||
|
||
/** | ||
* @hook validate artwork:show | ||
*/ | ||
public function artValidate(CommandData $commandData) | ||
{ | ||
$art = $commandData->input()->getArgument('art'); | ||
$data = $this->getArt(); | ||
if (!isset($data[$art])) { | ||
throw new \Exception(dt('I do not have any art called "{name}".', ['name' => $art])); | ||
} | ||
} | ||
|
||
/** | ||
* Get a list of available artwork. Cache result for future fast access. | ||
*/ | ||
protected function getArt() | ||
{ | ||
if (!isset($this->arts)) { | ||
$this->arts = $this->findArt(); | ||
} | ||
return $this->arts; | ||
} | ||
|
||
/** | ||
* Use custom defined on-event hook 'drush-art' to find available artwork. | ||
*/ | ||
protected function findArt() | ||
{ | ||
$arts = []; | ||
$handlers = $this->getCustomEventHandlers('drush-art'); | ||
foreach ($handlers as $handler) { | ||
$handlerResult = $handler(); | ||
$arts = array_merge($arts, $handlerResult); | ||
} | ||
return $arts; | ||
} | ||
|
||
/** | ||
* Given a list of artwork, converte to a 'key' => 'Name: Description' array. | ||
* @param array $data | ||
* @return array | ||
*/ | ||
protected function convertArtListToKeyValue($data) | ||
{ | ||
$result = []; | ||
foreach ($data as $key => $item) { | ||
$result[$key] = $item['name'] . ': ' . $item['description']; | ||
} | ||
return $result; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
I have discovered a truly marvelous proof that it is impossible to | ||
separate a piece of art into two cubes, or four pieces of art into two | ||
fourth of a piece of art, or in general, any artwork larger than the | ||
second into two like artistic expressions. | ||
|
||
This text file is too narrow to contain it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
|
||
.` | ||
`++++++++++ | ||
,'',+++#####++ | ||
;;,,,,++#######+ | ||
',,,,,++#######+ | ||
',,,,,++#######+: | ||
;,,,,:+########++ | ||
:,,,,'+########++ . | ||
.,,,,,++########++ ,'''';+++. | ||
,'+++. ;,,,,,++#########+ `',,,,,++#++: | ||
',++++++ ',,,,,++#########+; :;,,,,;++###++; | ||
',+++##+++` ';''++++#########+++++,,,,,+++#####++; | ||
',+++#####++'`'',;++++##############++++,,+++#######++. | ||
',;++#######+++,:+++'##################+++++##########++ | ||
',,++#########'++++'#######################+###########++ | ||
';'+++###########++####################################++ | ||
':::++#################################################+; | ||
':::++###############################################++ | ||
::::;++#############################################++ | ||
':::+++############################################+' | ||
':::++###########################################++ | ||
`;:::++##########################################+` | ||
':::;++#########################################++ | ||
''''++##########################################+: | ||
,,,,'+###########################################++ | ||
',,.++############################################+, | ||
`:,,;+#############################################++ | ||
',,,++##############################################+ | ||
',,,++##############################################++;. | ||
:,,,'+###############################################+++++++++: | ||
`;';,,++#####################################################++++' | ||
.'';,,,,,+++########################################################++ | ||
;';,,,,;++++++#########################################################++ | ||
;,;++++++++#############################################################+ | ||
,,,+++#################################################################++ | ||
.,,++###################################################################+ | ||
.,,++#################################################################@#+ | ||
.:,++############################,` .##################################++ | ||
`:,++########################## ################ #######+++++++ | ||
;,++########################: .############ ###++++++. | ||
',++#######################; ########## ###+: | ||
'++++##################### :###### :##+ | ||
:++++++++++#############` ###: .#++ | ||
,+++++############ :#++ | ||
',,;+############ ##+, | ||
;,,++########### `###, ##+ | ||
'::++########### ######' #++ | ||
;:;+########### ########## ##+` | ||
'::++########### :###' `#### #++ | ||
.':;+############ .#### #### ###++ | ||
',':++############; ###### ##### #####.,#####+, | ||
',,,:'++####################### ######.###########@++ | ||
:,,,,,++#########################################@@@++ | ||
',,,,,'+#########################################@@@@#+; | ||
:,,,,,,++################### `########+ #######@@@@@@++` | ||
',,,,,++##################### #######@@@@@@@@++ | ||
',,,,,'+#######################+ ;######+#@@@@@@@@@++ | ||
',,,,++####################################+++++@@@@@@@++ | ||
',,++####################################++;:'++#@@@@#+; | ||
''+###########+++#####################+++ '':+++@@#++ | ||
++#########+++:++++###############++++ ,'+++#++ | ||
.++#######+++ ,++++++##########+++ `'+++ | ||
.++#####++: ':;++++#########+; . | ||
`++###++ ;::::,++#######@+, | ||
+++++ ::::,++#####@@#+ | ||
++' ;:::,++##@@@@@#+ | ||
'::::;+@@@@@@@++ | ||
'::::,+#@@@@@@++ | ||
,'::,+#@@@@@@++ | ||
':,++@@@@@@+; | ||
':++@##++++. | ||
|
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a leftover sandwich mention.