register($options); $this->commandInstances[$command->getName()] = $command; } } /** * Your main program. * * Arguments and options have been parsed when this is run. * * @param Options $options * @return void */ protected function main(Options $options) { $commandName = $options->getCommand(); if (empty($commandName)) { echo $this->options->help(); exit(1); } if (! array_key_exists($commandName, $this->commandInstances)) { throw InvalidCommand::forUnregisteredCommand($commandName); } $command = $this->commandInstances[$commandName]; $command->process($options); } }