Scan the application for shells & commands.

@return array A list of command metadata.
973649
public function scanApp()
    {
        $appNamespace = Configure::read('App.namespace');
        $appShells = $this->scanDir(
            App::path('Shell')[0],
            $appNamespace . '\Shell\\',
            '',
            []
        );
        $appCommands = $this->scanDir(
            App::path('Command')[0],
            $appNamespace . '\Command\\',
            '',
            []
        );

        return array_merge($appShells, $appCommands);
    }
507802
protected function getCommandDescriptions()
    {
        $descriptions = [];
        foreach ($this->getCommands() as $command) {
            $description = '';

            $result = $this->app->createController($command);
            if ($result !== false && $result[0] instanceof Controller) {
                [$controller, $actionID] = $result;
                /** @var Controller $controller */
                $description = $controller->getHelpSummary();
            }

            $descriptions[$command] = $description;
        }

        return $descriptions;
    }
525016
public function getCommandCallbacks($command = null)
    {
        $result = array();
        if($command)
        {
            if(isset($this->__command_callbacks[$command])) {
                $result = $this->__command_callbacks[$command];
            }
        }
        else $result = $this->__command_callbacks;

        return $result;
    }
992133
public function getShellList()
    {
        $skipFiles = ['app'];
        $hiddenCommands = ['command_list', 'completion'];
        $plugins = Plugin::loaded();
        $shellList = array_fill_keys($plugins, null) + ['CORE' => null, 'app' => null];

        $appPath = App::path('Shell');
        $shellList = $this->_findShells($shellList, $appPath[0], 'app', $skipFiles);

        $appPath = App::path('Command');
        $shellList = $this->_findShells($shellList, $appPath[0], 'app', $skipFiles);

        $skipCore = array_merge($skipFiles, $hiddenCommands, $shellList['app']);
        $corePath = dirname(__DIR__);
        $shellList = $this->_findShells($shellList, $corePath, 'CORE', $skipCore);

        $corePath = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Command';
        $shellList = $this->_findShells($shellList, $corePath, 'CORE', $skipCore);

        foreach ($plugins as $plugin) {
            $pluginPath = Plugin::classPath($plugin) . 'Shell';
            $shellList = $this->_findShells($shellList, $pluginPath, $plugin, []);
        }

        return array_filter($shellList);
    }
139642
public function getProcessedHelp()
    {
        $help = $this->getHelp();
        if ($help === '') {
            return $help;
        }
        $name = $this->getName();

        $placeholders = ['%command.name%', '%command.full_name%'];
        $replacements = [$name, $this->config()->get('application.executable') . ' ' . $name];

        return str_replace($placeholders, $replacements, $help);
    }
214132
protected function getPhpMigCommands()
    {
        return [
            new Command\CheckCommand(),
            new Command\DownCommand(),
            new Command\GenerateCommand(),
            new Command\MigrateCommand(),
            new Command\RedoCommand(),
            new Command\RollbackCommand(),
            new Command\StatusCommand(),
            new Command\UpCommand(),
        ];
    }
1050675
public function getCommands()
    {
        foreach ($this->commands as $command) {
            if ($command instanceof \Traversable) {
                //Nested commands
                yield from $command;
            }

            yield $command;
        }
    }
1026296
protected function getDefaultCommands()
    {
        $commands = parent::getDefaultCommands();
        $commands[] = new Command\AboutCommand();
        $commands[] = new Command\ConfigCommand();
        $commands[] = new Command\DependsCommand();
        $commands[] = new Command\InitCommand();
        $commands[] = new Command\InstallCommand();
        $commands[] = new Command\CreateProjectCommand();
        $commands[] = new Command\UpdateCommand();
        $commands[] = new Command\SearchCommand();
        $commands[] = new Command\ValidateCommand();
        $commands[] = new Command\ShowCommand();
        $commands[] = new Command\RequireCommand();
        $commands[] = new Command\DumpAutoloadCommand();
        $commands[] = new Command\StatusCommand();
        $commands[] = new Command\ArchiveCommand();
        $commands[] = new Command\DiagnoseCommand();
        $commands[] = new Command\RunScriptCommand();
        $commands[] = new Command\LicensesCommand();
        $commands[] = new Command\GlobalCommand();
        $commands[] = new Command\ClearCacheCommand();
        $commands[] = new Command\RemoveCommand();
        $commands[] = new Command\HomeCommand();

        if ('phar:' === substr(__FILE__, 0, 5)) {
            $commands[] = new Command\SelfUpdateCommand();
        }

        return $commands;
    }
243909
public function getScanPaths()
    {
        $paths = $this->paths;

        $paths[] = $this->getPath().'/*';

        if ($this->config('scan.enabled')) {
            $paths = array_merge($paths, $this->config('scan.paths'));
        }

        return $paths;
    }
157630
public function meta()
    {
        try {
            $last = e($this->meta['scheduler']->last_run->diffForHumans());
        } catch (Exception $e) {
            $last = 'Never';
        }

        return [
            'Command' => e($this->meta['scheduler']->command),
            'Schedule' => e($this->meta['scheduler']->schedule),
            'Last Run' => $last
        ];
    }
185678
protected function getCommands(): array
	{
		$info = [];

		foreach($this->commands as $name => $class)
		{
			$command = $this->instantiateCommandWithoutConstructor($class);

			$info[$name] = [$name, $command->getCommandDescription()];
		}

		ksort($info);

		return $info;
	}
1104096
public function listCommand()
    {
        $head = ['Name', 'Stashed At', 'From Preset', 'Cloned At'];
        $rows = [];
        $basePath = sprintf(FLOW_PATH_ROOT . 'Data/MagicWandStash');

        if (!is_dir($basePath)) {
            $this->renderLine('Stash is empty.');
            $this->quit(1);
        }

        $baseDir = new \DirectoryIterator($basePath);
        $anyEntry = false;

        foreach ($baseDir as $entry) {
            if (!in_array($entry, ['.', '..'])) {
                $stashEntryName = $entry->getFilename();
                $manifest = $this->readStashEntryManifest($stashEntryName) ?: [];

                $rows[] = [
                    $stashEntryName,
                    $manifest['stashed_at'] ? date('Y-m-d H:i:s', $manifest['stashed_at']) : 'N/A',
                    isset($manifest['preset']['name']) ? $manifest['preset']['name'] : 'N/A',
                    $manifest['cloned_at'] ? date('Y-m-d H:i:s', $manifest['cloned_at']) : 'N/A',
                ];

                $anyEntry = true;
            }
        }

        if (!$anyEntry) {
            $this->renderLine('Stash is empty.');
            $this->quit(1);
        }

        $this->output->outputTable($rows, $head);
    }
511835
private function createCommandList()
    {
        $list = [];

        // read all core commands
        $this->listCommands($list, __DIR__ . '/../Commands', 'Core\Commands');

        // merge all plugin commands (plugin overrides the core)
        if (file_exists($this->pluginManifestOfCommands)) {
            /** @noinspection PhpIncludeInspection */
            $list = array_merge($list, include $this->pluginManifestOfCommands);
        }

        // merge all commands defined by application (application overrides all other)
        $this->listCommands($list, app_path('Commands'), 'App\Commands');

        // save the new command list
        ksort($list);

        return $list;
    }
1147730
protected function completeForCommandName()
    {
        if (!$this->command || (count($this->context->getWords()) == 2 && $this->context->getWordIndex() == 1)) {
            return $this->getCommandNames();
        }

        return false;
    }
766926
protected function getDefaultCommands()
    {
        $commands = parent::getDefaultCommands();
        $commands[] = new InitCommand();
        $commands[] = new InstallReleaseCommand();
        $commands[] = new DeployReleaseCommand();

        return $commands;
    }
178938
public function getMetaData()
    {
        if (count($this->command) == 0) {
            return ['console' => [
                'Command' => 'Command could not be retrieved', ],
            ];
        }
        $commandString = implode(' ', $this->command);
        $primaryCommand = $this->command[0];
        $arguments = [];
        $options = [];
        foreach (array_slice($this->command, 1) as $arg) {
            if (isset($arg[0]) && $arg[0] === '-') {
                $options[] = $arg;
            } else {
                $arguments[] = $arg;
            }
        }
        $data = [
            'Input' => $commandString,
            'Command' => $primaryCommand,
            'Arguments' => $arguments,
            'Options' => $options,
        ];

        return ['console' => $data];
    }
13703
protected function cmdListKeys()
    {
        /**
         * @see simplecomplex_cache_cli()
         */
        $container = Dependency::container();
        // Validate input. ---------------------------------------------
        $store = '';
        if (empty($this->command->arguments['store'])) {
            $this->command->inputErrors[] = !isset($this->command->arguments['store']) ? 'Missing \'store\' argument.' :
                'Empty \'store\' argument.';
        } else {
            $store = $this->command->arguments['store'];
            if (!CacheKey::validate($store)) {
                $this->command->inputErrors[] = 'Invalid \'store\' argument.';
            }
        }
        $expired = 0;
        if (!empty($this->command->arguments['expired'])) {
            if (!ctype_digit('' . $this->command->arguments['expired'])) {
                $this->command->inputErrors[] = 'Invalid \'expired\' argument, must be 0|1|2.';
            } else {
                $expired = (int) $this->command->arguments['expired'];
                switch ($expired) {
                    case 0:
                    case 1:
                    case 2:
                        break;
                    default:
                        $this->command->inputErrors[] = 'Invalid \'expired\' argument, must be 0|1|2.';
                }
            }
        }
        $limit = 0;
        if (!empty($this->command->arguments['limit'])) {
            if (!ctype_digit('' . $this->command->arguments['limit'])) {
                $this->command->inputErrors[] = 'Invalid \'limit\' argument, must be digit(s).';
            } else {
                $limit = (int) $this->command->arguments['limit'];
                if ($limit < 0) {
                    if ($limit == -1) {
                        $limit = 0;
                    } else {
                        $this->command->inputErrors[] = 'Invalid \'limit\' argument, cannot be less than.';
                    }
                }
            }
        }
        $end_of_life = '';
        if (!empty($this->command->arguments['end-of-life'])) {
            $end_of_life = $this->command->arguments['end-of-life'];
        }

        $get = !empty($this->command->options['get']);
        if ($get && $end_of_life) {
            $this->command->inputErrors[] = 'Option \'get\' is not compatible with non-empty argument end-of-life.';
        }

        if ($this->command->inputErrors) {
            foreach ($this->command->inputErrors as $msg) {
                $this->environment->echoMessage(
                    $this->environment->format($msg, 'hangingIndent'),
                    'notice'
                );
            }
            // This command's help text.
            $this->environment->echoMessage("\n" . $this->command);
            exit;
        }
        // Check if the command is doable.------------------------------
        // Does that store exist?
        if ($container->has('cache-broker')) {
            /** @var CacheBroker $cache_broker */
            $cache_broker_class = get_class($container->get('cache-broker'));
        } else {
            $cache_broker_class = static::CLASS_CACHE_BROKER;
        }
        $cache_class = constant($cache_broker_class . '::CACHE_CLASSES')[CacheBroker::CACHE_BASE];
        if (!method_exists($cache_class, 'listInstances')) {
            $this->environment->echoMessage('Cannot retrieve list of cache store instances via class['
                . $cache_class . '], has no static method listInstances().', 'error');
            exit;
        }
        $stores = forward_static_call($cache_class . '::listInstances');
        $cache_store = null;
        foreach ($stores as $instance) {
            if ($instance->name == $store) {
                /** @var ManageableCacheInterface $cache_store */
                $cache_store = $instance;
                break;
            }
        }
        if (!$cache_store) {
            $this->environment->echoMessage('');
            $this->environment->echoMessage('That cache store doesn\'t exist, store[' . $store . '].', 'warning');
            exit;
        }

        // Check that cache store class has listKeys() method
        // isn't an interface requirement.
        if (!method_exists($cache_store, 'listKeys')) {
            $this->environment->echoMessage('Cache store[' . $store . '] class[' . get_class($cache_store)
                . '] has no method listKeys().', 'error');
            exit;
        }

        /**
         * @see FileCache::listKeys()
         */
        $cache_keys = $cache_store->listKeys($expired, $limit, $end_of_life);
        if (!$end_of_life) {
            if ($get) {
                return join(',', $cache_keys);
            }
            $this->environment->echoMessage(join("\n", $cache_keys));
        }
        else {
            $buffer = '';
            foreach ($cache_keys as $key => $end_time) {
                $buffer .= $key . ': ' . $end_time . "\n";
            }
            $this->environment->echoMessage(rtrim($buffer));
        }
        exit;
    }