Skip to content

Commit

Permalink
Merge pull request #1206 from pantheon-systems/art-interact
Browse files Browse the repository at this point in the history
Add @hook interact to the art command.
  • Loading branch information
TeslaDethray committed Sep 15, 2016
2 parents 8dde1f0 + 4d00bb2 commit 57a0568
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 37 deletions.
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -7,6 +7,7 @@
"bin": [
"bin/terminus.bat", "bin/terminus"
],
"minimum-stability": "beta",
"require": {
"php": ">=5.5.9",
"consolidation/robo": "dev-master",
Expand Down
73 changes: 37 additions & 36 deletions composer.lock

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

51 changes: 50 additions & 1 deletion src/Commands/ArtCommand.php
Expand Up @@ -2,12 +2,18 @@

namespace Pantheon\Terminus\Commands;

use Symfony\Component\Finder\Finder;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class ArtCommand extends TerminusCommand
{
/**
* Displays Pantheon ASCII artwork
*
* @name art
* @command art
*
* @param string $name Name of the artwork to select
* @usage terminus art rocket
Expand All @@ -18,6 +24,24 @@ public function art($name) {
$this->io()->text("<comment>{$artwork_content}</comment>");
}

/**
* If the user does not specify the $name parameter, then we will
* prompt for it here.
*
* @hook interact
*/
public function interact(InputInterface $input, OutputInterface $output)
{
$available_art = $this->availableArt();

$io = new SymfonyStyle($input, $output);
$art_name = $input->getArgument('name');
if (!$art_name) {
$art_name = $io->choice('Select art:', $available_art, 'fist');
$input->setArgument('name', $art_name);
}
}

/**
* @param $name
* @return string
Expand All @@ -43,4 +67,29 @@ private function validateAsset($file_path)
{
return file_exists($file_path);
}

/**
* Return available art
* @return array
*/
protected function availableArt()
{
// Find all of the art in the assets directory.
$finder = new Finder();
$finder
->files()
->in($this->config->get('assets_dir'))
->depth('== 0')
->name('*.txt')
->sortbyname();

return array_values(
array_map(
function ($file) {
return $file->getBasename('.txt');
},
(array) $finder->getIterator()
)
);
}
}

0 comments on commit 57a0568

Please sign in to comment.