Output help for a certain command or the current command if a help option is specified
@param string|null $command
330633
public function outputHelp($command = null)
    {
        $help_options = $this->config->get('cli_help_option', 'h');

        if (isset($command) || $this->getParam($help_options)) {

            if (!isset($command)) {
                $command = $this->command;
            }

            $aliases = $this->route->getAliases();

            if (isset($aliases[$command])) {
                $command = $aliases[$command];
            }

            $routes = $this->route->getList();

            if (empty($routes[$command])) {
                $this->errorAndExit($this->text('Unknown command'));
            }

            $this->printHelpText($routes[$command]);
            $this->output();
        }
    }
125019
protected static function showHelp()
    {
        \cli\line();
        \cli\out(self::$arguments->getHelpScreen(\cli\Colors::colorize('%N%n%gAvailable commands:')));
        \cli\line();
    }
81631
protected function doAction(Command $command)
    {
        if ($command->name() === '__default__') {
            return $this->notFound();
        }

        // Let the command collect more data (if missing or needs confirmation)
        $command->interact($this->io());

        if (!$command->action() && !\method_exists($command, 'execute')) {
            return;
        }

        $params = [];
        $values = $command->values();
        // We prioritize action to be in line with commander.js!
        $action = $command->action() ?? [$command, 'execute'];

        foreach ($this->getActionParameters($action) as $param) {
            $params[] = $values[$param->getName()] ?? null;
        }

        return $action(...$params);
    }
1232751
final public function handle(Command $command): void
    {
        if (!$command instanceof ReceivedCommand && $this->discriminator->shouldEnqueue($command)) {
            $this->queue->send($command);

            return;
        }

        if ($command instanceof ReceivedCommand) {
            $command = $command->getOriginalCommand();
        }

        $this->wrappedCommandBus->handle($command);
    }
1009586
public function addConsole($command) {
        /* @var $command Command */
        $command->configure();
        $name = $command->name();
        $this->defaultCommand[ $name ] = $command;
    }
718411
private function getCommandFromHelpCommand(HelpCommand $helpCommand)
    {
        // hackish way of retrieving the command for which help was asked
        $reflectionObject = new \ReflectionObject($helpCommand);
        $commandProperty = $reflectionObject->getProperty('command');
        $commandProperty->setAccessible(true);

        return $commandProperty->getValue($helpCommand);
    }
305661
public function helpStubCommand()
    {
        $context = $this->bootstrap->getContext();
        $applicationPackage = $this->packageManager->getPackage($this->applicationPackageKey);
        $this->outputLine('<b>%s %s ("%s" context)</b>', [$this->applicationName, $applicationPackage->getInstalledVersion() ?: 'dev', $context]);
        $this->outputLine('<i>usage: %s <command identifier></i>', [$this->getFlowInvocationString()]);
        $this->outputLine();
        $this->outputLine('See "%s help" for a list of all available commands.', [$this->getFlowInvocationString()]);
        $this->outputLine();
    }
377182
protected function printHelpText(array $command)
    {
        $shown = false;

        if (!empty($command['description'])) {
            $shown = true;
            $this->line($this->text($command['description']));
        }

        if (!empty($command['usage'])) {

            $shown = true;
            $this->line()->line($this->text('Usage:'));

            foreach ($command['usage'] as $usage) {
                $this->line($usage);
            }
        }

        if (!empty($command['options'])) {

            $shown = true;
            $this->line()->line($this->text('Options:'));

            foreach ($command['options'] as $name => $description) {
                $vars = array('@option' => $name, '@description' => $this->text($description));
                $this->line($this->text('  @option  @description', $vars));
            }
        }

        if (!$shown) {
            $this->line($this->text('No help found for the command'));
        }
    }
285224
private function call($command)
    {
        if (!in_array($command, static::COMMAND)) {
            $this->throwFailsCommand("The command '$command' not exists.", 'help');
        }

        if (!$this->arg->getParameter('action')) {
            if ($this->arg->getParameter('target') == 'help') {
                $this->help($command);

                exit(0);
            }
        }

        try {
            call_user_func_array(
                [$this, $command],
                [$this->arg->getParameter('target')]
            );
        } catch (\Exception $e) {
            echo $e->getMessage();

            exit(1);
        }
    }
456638
public function getCommand($name = null)
    {
        if ($name !== null) {
            return isset($this->commands[$name]) ? $this->commands[$name] : null;
        }

        return $this->command;
    }
977988
public static function routeCommand($command = 'help')
	{
		// Aliases take precedence, so parse for them first
		if ($aliases = Config::get('aliases'))
		{
			if (array_key_exists($command, $aliases))
			{
				if (strpos($aliases->$command, '::') !== false)
				{
					$bits      = explode('::', $aliases->$command);
					$command   = $bits[0];
					$aliasTask = $bits[1];
				}
				else
				{
					$command = $aliases->$command;
				}
			}
		}

		foreach (self::$commandNamespaces as $namespace)
		{
			// Check if we're targeting a namespaced command
			$bits = [];
			if (strpos($command, ':'))
			{
				$bits = explode(':', $command);
			}
			else
			{
				$bits[] = $command;
			}

			$bits = array_map('ucfirst', $bits);

			// Replace any inset placeholders
			for ($i = 0; $i < count($bits); $i++)
			{
				$loc = $i + 1;
				if (strpos($namespace, "{\$$loc}"))
				{
					$namespace = str_replace("{\$$loc}", $bits[$i], $namespace);
					unset($bits[$i]);
				}
			}

			// Add any remaining bits to the end of the command namespace
			if (count($bits) > 0)
			{
				$namespace .= '\\' . implode('\\', $bits);
			}

			// Check for existence
			if (class_exists($namespace))
			{
				$class = $namespace;
				break;
			}
		}

		if (!isset($class))
		{
			throw new UnsupportedCommandException("Unknown command: {$command}.");
		}

		return $class;
	}
1013538
public function getHelp()
    {
        print Color::head('Help:') . PHP_EOL;
        print Color::colorize('  Lists the commands available in Console') . PHP_EOL . PHP_EOL;

        $this->run([]);
    }
1130097
public function addCommand($command)
    {
        if (is_string($command)) {
            $command = $this->app->make($command);
        }

        if ($command instanceof Command) {
            $command->setLaravel($this->app);
        }

        $this->console->add($command);
    }
1171939
public void printHelp(Command command) {
        if (command.getDescriptor().getUsage() != null) {
            printUsage(command.getDescriptor().getUsage());
        } else {
            printUsage(command);
        }
        int leftWidth = printOptions(command.getOptions());
        printArguments(command.getArgumentsList(), leftWidth);
    }
365736
private void determineCommand() {
        command = null;
        commandStr = null;

        boolean tooManyCommands = false;
        for (Command c : Command.values()) {
            final String alias = c.getAlias();
            if (hasOption(alias)) {
                if (c == Command.HELP) {
                    // `--help` can be a command or just a long option for another command.
                    help = true;
                } else if (command == null) {
                    // Found a command option
                    command = c;
                    commandStr = alias;
                } else {
                    tooManyCommands = true;
                }
            }
        }

        if (tooManyCommands) {
            command = null;
            commandStr = null;

            if (!help) {
                reportable.error(format(
                        "You must specify only one command (%s).%n",
                        showCommandAliases()));
                printHelp(true);
            }
        }
        if (help && command == null) {
            // `--help` is considered as the command if no other command is provided.
            command = Command.HELP;
            commandStr = command.getAlias();

        } else if (command == null) {
        	// Print usage if no commands were specified
        	printUsage();
        	reportable.error("\n");
            reportable
                    .error("No command option given. Please specify one of:  "
                            + showCommandAliases());
            end();
        }
    }
538631
public function showHelpInfo(string $command = ''): void
    {
        /** @var \Inhere\Console\IO\Input $in */
        $in = $this->input;

        // display help for a special command
        if ($command) {
            $in->setCommand($command);
            $in->setSOpt('h', true);
            $in->clearArgs();
            $this->dispatch($command);
            return;
        }

        $sep    = $this->delimiter;
        $script = $in->getScript();

        /** @var \Inhere\Console\IO\Output $out */
        $out = $this->output;
        $out->helpPanel([
            'usage'   => "$script <info>{command}</info> [--opt -v -h ...] [arg0 arg1 arg2=value2 ...]",
            'example' => [
                "$script test (run a independent command)",
                "$script home{$sep}index (run a command of the group)",
                "$script help {command} (see a command help information)",
                "$script home{$sep}index -h (see a command help of the group)",
                "$script --auto-completion --shell-env [zsh|bash] [--gen-file stdout]",
            ]
        ]);
    }
1366159
private static function isCommandAvailable(string $command): bool
    {
        if (!is_callable('shell_exec') || stripos(ini_get('disable_functions'), 'shell_exec') !== false) {
            return false;
        }

        $result = null;
        if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') {
            $result = @shell_exec('which '.$command);
        }

        return !empty($result);
    }