52 lines
1.4 KiB
Plaintext
52 lines
1.4 KiB
Plaintext
|
|
#!/usr/bin/env php
|
||
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace {
|
||
|
|
// Ensure composer autoload is available whether this is run from repo or installed project
|
||
|
|
$autoloadPaths = [
|
||
|
|
__DIR__ . '/../vendor/autoload.php', // project root vendor
|
||
|
|
__DIR__ . '/../../autoload.php', // vendor/bin scenario
|
||
|
|
];
|
||
|
|
$autoloaded = false;
|
||
|
|
foreach ($autoloadPaths as $path) {
|
||
|
|
if (is_file($path)) {
|
||
|
|
require $path;
|
||
|
|
$autoloaded = true;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (!$autoloaded) {
|
||
|
|
fwrite(STDERR, "Unable to locate Composer autoload.\n");
|
||
|
|
exit(1);
|
||
|
|
}
|
||
|
|
|
||
|
|
$app = new \Symfony\Component\Console\Application('Phred', '0.1');
|
||
|
|
|
||
|
|
// Discover core commands bundled with Phred (moved under src/commands)
|
||
|
|
$coreDir = dirname(__DIR__) . '/src/commands';
|
||
|
|
if (is_dir($coreDir)) {
|
||
|
|
foreach (glob($coreDir . '/*.php') as $file) {
|
||
|
|
$cmd = require $file;
|
||
|
|
if ($cmd instanceof \Phred\Console\Command) {
|
||
|
|
$app->add($cmd->toSymfony());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Discover user commands in console/commands
|
||
|
|
$userDir = getcwd() . '/console/commands';
|
||
|
|
if (is_dir($userDir)) {
|
||
|
|
foreach (glob($userDir . '/*.php') as $file) {
|
||
|
|
$cmd = require $file;
|
||
|
|
if ($cmd instanceof \Phred\Console\Command) {
|
||
|
|
$app->add($cmd->toSymfony());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Run
|
||
|
|
$app->run();
|
||
|
|
}
|