Skip to content

Commit

Permalink
[BUGS-7540] Add art:list command (#2554)
Browse files Browse the repository at this point in the history
* Add art:list command
* Correct art command documentation

---------

Co-authored-by: Kyle Taylor <[email protected]>
  • Loading branch information
kporras07 and Kyle Taylor authored Feb 28, 2024
1 parent 681e385 commit df8cf8e
Showing 1 changed file with 52 additions and 5 deletions.
57 changes: 52 additions & 5 deletions src/Commands/ArtCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,45 @@

use Pantheon\Terminus\Exceptions\TerminusNotFoundException;
use Pantheon\Terminus\Helpers\LocalMachineHelper;
use Consolidation\OutputFormatters\StructuredData\RowsOfFields;

/**
* Class ArtCommand
* @package Pantheon\Terminus\Commands
*/
class ArtCommand extends TerminusCommand
{
use StructuredListTrait;

/**
* @var array
*/
protected $available_art = ['druplicon', 'fist', 'hello', 'rocket', 'unicorn', 'wordpress',];
protected $available_art = [
'druplicon' => [
'name' => 'druplicon',
'description' => 'The mascot of Drupal'
],
'fist' => [
'name' => 'fist',
'description' => 'The fist of Zeus',
],
'hello' => [
'name' => 'hello',
'description' => 'A welcome from Terminus',
],
'rocket' => [
'name' => 'rocket',
'description' => 'A rocket ship',
],
'unicorn' => [
'name' => 'unicorn',
'description' => 'A wonderful unicorn',
],
'wordpress' => [
'name' => 'wordPress',
'description' => 'The WordPress logo',
],
];

/**
* Displays Pantheon ASCII artwork.
Expand All @@ -23,17 +51,36 @@ class ArtCommand extends TerminusCommand
*
* @param string $name Artwork name
*
* @usage Displays the list of available artwork.
* @usage <artwork> Displays the <artwork> artwork.
*/
public function art($name = 'random')
{
if ($name == 'random') {
$name = $this->randomArtName();
$name = $this->randomArtName()['name'];
}
return $this->retrieveArt($name);
}

/**
* Lists available Pantheon ASCII artwork.
*
* @command art:list
*
* @field-labels
* name: Name
* description: Description
*
* @default-fields name,description
*
* @usage Displays the list of available artwork.
*
* @return RowsOfFields
*/
public function listArt()
{
return new RowsOfFields($this->available_art);
}

/**
* Set the art filename.
*
Expand All @@ -52,7 +99,7 @@ protected function getFilename($name)
*/
protected function randomArtName()
{
return $this->available_art[array_rand($this->available_art)];
return $this->available_art[array_rand($this->available_art, 1)];
}

/**
Expand All @@ -68,7 +115,7 @@ protected function retrieveArt($name)
$local_machine_helper = $this->getContainer()->get(LocalMachineHelper::class);
if (!$local_machine_helper->getFilesystem()->exists($filename)) {
throw new TerminusNotFoundException(
'There is no source for the requested {name} artwork.',
'There is no source for the requested "{name}" artwork.',
compact('name')
);
}
Expand Down

0 comments on commit df8cf8e

Please sign in to comment.