$argc = 2; } // Create a little cache for the Help command, if applicable. Doesn't contain objects. $commands = []; foreach (\glob(__DIR__ . '/Commands/*.php') as $file) { // Let's build a queue of all the file names // Grab the filename from the Commands directory: $className = \preg_replace('#.*/([A-Za-z0-9_]+)\\.php$#', '$1', $file); $index = \strtolower($className); // Append to $commands array $commands[$index] = $className; if ($argv[1] !== 'help') { // If this is the command the user passed... if ($index === $argv[1]) { // Instantiate this object $exec = Command::getCommandStatic($className); // Store the relevant storage devices in the command, in case they're needed $exec->storeConfig($config); // Execute it, passing the extra parameters to the command's fire() method try { $exec->fire(\array_values(\array_slice($argv, 2))); } catch (\Exception $e) { echo $e->getMessage(), "\n"; $code = $e->getCode(); exit($code > 0 ? $code : 255); } $exec->saveConfig(); exit(0); } } }