Skip to content

Commit

Permalink
adding inventory command
Browse files Browse the repository at this point in the history
  • Loading branch information
stovak committed Dec 11, 2023
1 parent bd06590 commit af09ff9
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 15 deletions.
2 changes: 1 addition & 1 deletion bin/terminus
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if (!getenv('TERMINUS_ALLOW_UNSUPPORTED_NEWER_PHP') && version_compare(PHP_VERSI

// This variable is automatically managed via updateDependenciesversion() in /RoboFile.php,
// which is run after every call to composer update.
$terminusPluginsDependenciesVersion = 'f512ad328f';
$terminusPluginsDependenciesVersion = '284a60df18';

// Cannot use $_SERVER superglobal since that's empty during phpunit testing
// getenv('HOME') isn't set on Windows and generates a Notice.
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"monolog/monolog": "^2.2",
"psy/psysh": "^0.11.9",
"rogervila/array-diff-multidimensional": "^2.0",
"symfony/console": "^5",
"symfony/console": "^5.4",
"symfony/finder": "^5",
"symfony/process": "^5",
"symfony/yaml": "^5",
Expand Down Expand Up @@ -105,6 +105,9 @@
"code:lint": [
"@cs"
],
"code:inventory": [
"\\Terminus\\UpdateClassLists::getCommandModelsAndCollections > ~/go/src/github.com/pantheon-systems/pantheonapi/docs/terminus_inventory.md"
],
"code:new-command": [
"rm -Rf ~/.terminus/cache/commands || true",
"@update-class-lists",
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

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

60 changes: 54 additions & 6 deletions scripts/UpdateClassLists.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
namespace Terminus;

use Consolidation\AnnotatedCommand\CommandFileDiscovery;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Console\Output\ConsoleOutput;


class UpdateClassLists
{
static function update()
public static function update()
{
$base = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR;
$commands = static::getCommands(
Expand Down Expand Up @@ -56,7 +59,7 @@ function ($item) {
file_put_contents($srcPath, $contents);
}

static function generateAddToContainerCode($what, $classList)
public static function generateAddToContainerCode($what, $classList)
{
sort($classList);

Expand All @@ -82,7 +85,7 @@ function ($item) {
* string namespace The full namespace associated with given the command directory
* @return TerminusCommand[] An array of TerminusCommand instances
*/
static function getCommands($path, $baseNamespace)
public static function getCommands($path, $baseNamespace)
{
$discovery = new CommandFileDiscovery();
$discovery->setSearchPattern('*Command.php')->setSearchLocations([]);
Expand All @@ -97,7 +100,7 @@ static function getCommands($path, $baseNamespace)
* string namespace The full namespace associated with given the hooks directory
* @return array An array of hook instances
*/
static function getHooks($path, $baseNamespace)
public static function getHooks($path, $baseNamespace)
{
$discovery = new CommandFileDiscovery();
$discovery->setSearchPattern('*.php')->setSearchLocations([]);
Expand All @@ -109,7 +112,7 @@ static function getHooks($path, $baseNamespace)
*
* @param string $path
*/
static function getClassesInDir($path)
public static function getClassesInDir($path)
{
$result = [];
$files = Finder::create()->files()->in($path)->name('*.php');
Expand All @@ -124,4 +127,49 @@ static function getClassesInDir($path)
return $result;
}

}
public static function getCommandModelsAndCollections()
{
$base = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR;
$commands = static::getCommands(
$base . 'Commands',
'Pantheon\Terminus\Commands'
);
$hooks = static::getHooks(
$base . 'Hooks',
'Pantheon\Terminus\Hooks'
);
$models = static::getClassesInDir($base . 'Models');
$collections = static::getClassesInDir($base . 'Collections');

$output = new ConsoleOutput();
$output->setDecorated(true);
$commandTable = new Table($output);
$commandTable->setHeaders(["Commands"]);
$commandTable->setRows(array_map(
function ($item) {
return [ str_replace("Pantheon\Terminus\Commands", "", $item) ];
},
$commands
));
$modelsTable = new Table($output);
$modelsTable->setHeaders(["Models"]);
$modelsTable->setRows(array_map(
function ($item) {
return [str_replace("\Pantheon\Terminus\Models", "", $item)];
},
$models
));
$collectionsTable = new Table($output);
$collectionsTable->setHeaders(["Collections"]);
$collectionsTable->setRows(array_map(
function ($item) {
return [str_replace("\Pantheon\Terminus\Collections", "", $item)];
},
$collections
));
$commandTable->render();
$modelsTable->render();
$collectionsTable->render();
}

}

0 comments on commit af09ff9

Please sign in to comment.