#!/usr/bin/env php $argv[1] ?? 'help']; for ($i = 2; $i < count($argv); $i++) { $a = $argv[$i]; if (str_starts_with($a, '--')) { $eq = strpos($a, '='); if ($eq !== false) { $key = substr($a, 2, $eq - 2); $val = substr($a, $eq + 1); $args[$key] = $val; } else { $key = substr($a, 2); $args[$key] = true; } } else { $args[] = $a; } } return $args; } function cmd_help(): void { $help = << MigrateCommand::class, 'rollback' => RollbackCommand::class, 'status' => StatusCommand::class, 'reset' => ResetCommand::class, 'make:migration' => MakeMigrationCommand::class, 'mongo:index:ensure' => MongoIndexEnsureCommand::class, 'mongo:index:drop' => MongoIndexDropCommand::class, 'mongo:index:list' => MongoIndexListCommand::class, ]; if ($cmd === 'help' || !isset($commands[$cmd])) { cmd_help(); exit($cmd === 'help' ? 0 : 1); } try { $class = $commands[$cmd]; /** @var \Pairity\Console\CommandInterface $instance */ $instance = new $class(); $instance->execute($args); } catch (\Throwable $e) { fwrite(STDERR, 'Error: ' . $e->getMessage() . PHP_EOL); exit(1); }