refactor: console improvements — auto-discovery, centralized bootstrap, per-command help

- ConsoleApplication.discoverCommands() scans lib/Console/Commands/ automatically;
  adding a new command no longer requires editing bin/console
- Command base class provides bootstrapApp(), bootstrapModuleApp(), requireBinScript()
  and projectRoot() helpers — eliminates fragile 4-level relative require_once paths
- Per-command --help support via optional usage() method on Command
- Docker-compose scheduler updated to use bin/console scheduler:run
- Old bin scripts now emit deprecation hint to stderr when called directly

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-19 19:16:36 +01:00
parent f7787465f7
commit ba1186c525
21 changed files with 269 additions and 45 deletions

View File

@@ -9,35 +9,17 @@ declare(strict_types=1);
* Usage:
* php bin/console <command> [arguments] [options]
* php bin/console list
* php bin/console <command> --help
*
* Examples:
* php bin/console module:sync
* php bin/console module:deactivate addressbook --confirm
* php bin/console scheduler:run
* php bin/console doctor
* Commands are auto-discovered from lib/Console/Commands/.
* To add a new command, create a class extending Command in that directory.
*/
require_once __DIR__ . '/../vendor/autoload.php';
use MintyPHP\Console\ConsoleApplication;
use MintyPHP\Console\Commands\DoctorCommand;
use MintyPHP\Console\Commands\Module\AssetsSyncCommand;
use MintyPHP\Console\Commands\Module\BuildCommand;
use MintyPHP\Console\Commands\Module\DeactivateCommand;
use MintyPHP\Console\Commands\Module\MigrateCommand;
use MintyPHP\Console\Commands\Module\PermissionsSyncCommand;
use MintyPHP\Console\Commands\Module\RuntimeSyncCommand;
use MintyPHP\Console\Commands\Scheduler\RunCommand;
$app = new ConsoleApplication();
$app->register(new RuntimeSyncCommand());
$app->register(new MigrateCommand());
$app->register(new PermissionsSyncCommand());
$app->register(new BuildCommand());
$app->register(new AssetsSyncCommand());
$app->register(new DeactivateCommand());
$app->register(new RunCommand());
$app->register(new DoctorCommand());
$app->discoverCommands(__DIR__ . '/../lib/Console/Commands');
exit($app->run($argv));

View File

@@ -56,5 +56,6 @@ function moduleAssetsSyncRun(): int
}
if (PHP_SAPI === 'cli' && realpath((string) ($_SERVER['SCRIPT_FILENAME'] ?? '')) === __FILE__) {
fwrite(STDERR, "Hint: prefer `php bin/console module:assets-sync` instead.\n");
exit(moduleAssetsSyncRun());
}

View File

@@ -63,5 +63,6 @@ function moduleBuildRun(): int
}
if (PHP_SAPI === 'cli' && realpath((string) ($_SERVER['SCRIPT_FILENAME'] ?? '')) === __FILE__) {
fwrite(STDERR, "Hint: prefer `php bin/console module:build` instead.\n");
exit(moduleBuildRun());
}

View File

@@ -85,5 +85,6 @@ function moduleDeactivateRun(): int
}
if (PHP_SAPI === 'cli' && realpath((string) ($_SERVER['SCRIPT_FILENAME'] ?? '')) === __FILE__) {
fwrite(STDERR, "Hint: prefer `php bin/console module:deactivate` instead.\n");
exit(moduleDeactivateRun());
}

View File

@@ -246,5 +246,6 @@ function moduleMigrateSplitSqlStatements(string $sql): array
}
if (PHP_SAPI === 'cli' && realpath((string) ($_SERVER['SCRIPT_FILENAME'] ?? '')) === __FILE__) {
fwrite(STDERR, "Hint: prefer `php bin/console module:migrate` instead.\n");
exit(moduleMigrateRun());
}

View File

@@ -50,5 +50,6 @@ function modulePermissionsSyncRun(): int
}
if (PHP_SAPI === 'cli' && realpath((string) ($_SERVER['SCRIPT_FILENAME'] ?? '')) === __FILE__) {
fwrite(STDERR, "Hint: prefer `php bin/console module:permissions-sync` instead.\n");
exit(modulePermissionsSyncRun());
}

View File

@@ -72,5 +72,6 @@ function moduleRuntimeSyncRun(): int
}
if (PHP_SAPI === 'cli' && realpath((string) ($_SERVER['SCRIPT_FILENAME'] ?? '')) === __FILE__) {
fwrite(STDERR, "Hint: prefer `php bin/console module:sync` instead.\n");
exit(moduleRuntimeSyncRun());
}

View File

@@ -9,6 +9,7 @@ use MintyPHP\Service\Scheduler\SchedulerServicesFactory;
require_once __DIR__ . '/cli-bootstrap.php';
fwrite(STDERR, "Hint: prefer `php bin/console scheduler:run` instead.\n");
$exitCode = 0;
$startedAt = microtime(true);
try {