|null $commandArguments The command new arguments */ public function __construct (string|Command $commandName, CommandArgumentList|Arrayy|null $commandArguments = null) { $this->setCommandName($commandName); $this->setCommandArguments($commandArguments ?? new CommandArgumentList()); } /** * Generate the input for the command call * * @return InputInterface Generate the input for the command call */ public function generateInput (): InputInterface { return new ArrayInput( array_merge( [ 'command' => $this->getCommandName(), ], $this->getCommandArguments()->getArguments() ) ); } /** * Run the command * * @param Application $app The application * @param OutputInterface $output The output * * @return int The command return code * * @throws Throwable If an error occurs */ public function run (Application $app, OutputInterface $output): int { return $app->doRun($this->generateInput(), $output); } /** * The command name * * @return string The command name */ public function getCommandName (): string { return $this->commandName; } /** * Set the command name * * @param string|Command $commandName The new command name * * @return $this */ public function setCommandName (string|Command $commandName): self { $this->commandName = $commandName instanceof Command ? CliHelper::getCommandNameFromClass($commandName->getApplication(), $commandName::class) : $commandName; return $this; } /** * The command arguments * * @return Arrayy The command arguments */ public function getCommandArguments (): CommandArgumentList { return $this->commandArguments; } /** * Set the command arguments * * @param CommandArgumentList|Arrayy $commandArguments The command new arguments * * @return $this */ public function setCommandArguments (CommandArgumentList|Arrayy $commandArguments): self { $this->commandArguments = $commandArguments instanceof CommandArgumentList ? $commandArguments : new CommandArgumentList($commandArguments); return $this; } }