Converts commands to text

@return string The commands as text
975695
private function getCommandText() : string
    {
        if (count($this->commandCollection->getAll()) === 0) {
            return '  <info>No commands</info>';
        }

        /**
         * Sorts the commands by name
         * Uncategorized (commands without ":" in their names) always come first
         *
         * @param ICommand $a
         * @param ICommand $b
         * @return int The result of the comparison
         */
        $sort = function ($a, $b) {
            if (strpos($a->getName(), ':') === false) {
                if (strpos($b->getName(), ':') === false) {
                    // They're both uncategorized
                    return $a->getName() < $b->getName() ? -1 : 1;
                } else {
                    // B is categorized
                    return -1;
                }
            } else {
                if (strpos($b->getName(), ':') === false) {
                    // A is categorized
                    return 1;
                } else {
                    // They're both categorized
                    return $a->getName() < $b->getName() ? -1 : 1;
                }
            }
        };

        $commands = $this->commandCollection->getAll();
        usort($commands, $sort);
        $categorizedCommandNames = [];
        $commandTexts = [];
        $firstCommandNamesToCategories = [];

        foreach ($commands as $command) {
            $commandNameParts = explode(':', $command->getName());

            if (count($commandNameParts) > 1 && !in_array($commandNameParts[0], $firstCommandNamesToCategories)) {
                $categorizedCommandNames[] = $command->getName();

                // If this is the first command for this category
                if (!in_array($commandNameParts[0], $firstCommandNamesToCategories)) {
                    $firstCommandNamesToCategories[$command->getName()] = $commandNameParts[0];
                }
            }

            $commandTexts[] = [$command->getName(), $command->getDescription()];
        }

        return $this->paddingFormatter->format($commandTexts,
            function ($row) use ($categorizedCommandNames, $firstCommandNamesToCategories) {
                $output = '';

                // If this is the first command of its category, display the category
                if (in_array(trim($row[0]),
                        $categorizedCommandNames) && isset($firstCommandNamesToCategories[trim($row[0])])
                ) {
                    $output .= "<comment>{$firstCommandNamesToCategories[trim($row[0])]}</comment>" . PHP_EOL;
                }

                return $output . "  <info>{$row[0]}</info> - {$row[1]}";
            });
    }
621283
protected function command()
    {
        $command = 'php artisan spark:install --force';

        if ($this->command->input->getOption('braintree')) {
            $command .= ' --braintree';
        }

        if ($this->command->input->getOption('team-billing')) {
            $command .= ' --team-billing';
        }

        return $command;
    }
1257570
def help_text(self):
        
        help_text = '\n'.join(sorted(get_commands().keys()))
        help_text = "\nCommands:\n" + help_text
        return help_text
328224
protected function _buildCommand()
    {
        $command = $this->_binary;
        $options = (array)$this->getConfig('options');
        foreach ($options as $key => $value) {
            if (empty($value)) {
                continue;
            } elseif ($value === true) {
                $command .= ' --' . $key;
            } else {
                $command .= sprintf(' --%s %s', $key, escapeshellarg($value));
            }
        }

        return $command;
    }
1023975
protected function getCommands()
    {
        $commands = [];

        foreach ($this->getApplication()->all() as $name => $command) {
            if (in_array($name, $this->commandWhitelist)) {
                $commands[] = $command;
            }
        }

        foreach (config('tinker.commands', []) as $command) {
            $commands[] = $this->getApplication()->resolve($command);
        }

        return $commands;
    }
627969
private static String showCommandAliases() {
        final Command[] commands = Command.values();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < commands.length; ++i) {
            if (i != 0) {
                sb.append(", ");
                if (i == commands.length - 1) {
                    sb.append("or ");
                }
            }
            sb.append("`--");
            sb.append(commands[i].getAlias());
            sb.append("`");
        }
        return sb.toString();
    }
127410
public function getTextOutput()
    {
        $patchLevel = $this->getPatchLevel();

        $commands     = array(sprintf('-- Patch level %d structural changes', $patchLevel));
        $lastLocation = '';
        $lastName     = '';
        $noOutput     = true;
        foreach ($this->getStructuralPatches($patchLevel) as $patch) {
            if ($patch['gpa_location'] != $lastLocation) {
                $commands[] = sprintf("\n-- DATABASE LOCATION: %s", $patch['gpa_location']);
                $lastLocation = $patch['gpa_location'];
            }
            if ($patch['gpa_name'] != $lastName) {
                $commands[] = sprintf("\n-- PATCH: %s", $patch['gpa_name']);
                $lastName = $patch['gpa_name'];
            }
            $commands[] = $patch['gpa_sql'] . ';';
            $noOutput = false;
        }

        if ($noOutput) {
            $commands[] = sprintf("\n-- No structural changes in patchlevel %d", $patchLevel);
        }
        $commands[] = '';

        return implode("\n", $commands);
    }
814431
private function formatCommand()
    {
        $cmdGroup = [];
        $noGroup = [];
        foreach ($this->console->getCommands() as $name => $class) {
            if ($class !== __CLASS__) {
                $class = new \ReflectionClass($class);
                $property = $class->getDefaultProperties();
                $property = isset($property['description']) ? $property['description'] : '';

                $hadGroup = strpos($name, ':');
                $group = substr($name, 0, $hadGroup);
                $name = Colour::colour($name, Colour::GREEN);
                $this->commandLength > strlen($name) || $this->commandLength = strlen($name) + 3;

                if ($hadGroup) {
                    $cmdGroup[$group][$name] = $property;
                } else {
                    $noGroup[$name] = $property;
                }
            }
        }
        return [$noGroup, $cmdGroup];
    }
1034780
public function decodeText($commands)
    {
        $word_position = 0;
        $words         = array();
        $unicode       = false;
        $font_space    = $this->getFontSpaceLimit();

        foreach ($commands as $command) {
            switch ($command[PDFObject::TYPE]) {
                case 'n':
                    if (floatval(trim($command[PDFObject::COMMAND])) < $font_space) {
                        $word_position = count($words);
                    }
                    continue(2);

                case '<':
                    // Decode hexadecimal.
                    $text = self::decodeHexadecimal('<' . $command[PDFObject::COMMAND] . '>');

                    if (mb_check_encoding($text, "UTF-8")) {
                        $unicode = true;
                    }

                    break;

                default:
                    // Decode octal (if necessary).
                    $text = self::decodeOctal($command[PDFObject::COMMAND]);
            }

            // replace escaped chars
            $text = str_replace(
                array('\\\\', '\(', '\)', '\n', '\r', '\t', '\ '),
                array('\\', '(', ')', "\n", "\r", "\t", ' '),
                $text
            );

            // add content to result string
            if (isset($words[$word_position])) {
                $words[$word_position] .= $text;
            } else {
                $words[$word_position] = $text;
            }
        }

        foreach ($words as &$word) {
            $loop_unicode = $unicode;
            $word         = $this->decodeContent($word, $loop_unicode);
        }

        return implode(' ', $words);
    }
1257533
public function getBuiltCommand()
    {
        $cmd = $this->command;

        foreach ($this->arguments as $argument) {
            $os = $argument->getOs();

            if ($os && !($os & $this->os->getType())) {
                continue;
            }

            $key = $argument->getKey();
            $prefix = $argument->getPrefix();

            if ($argument->willEscape() === true || ($argument->willEscape() === null && ($this->flags & ESCAPE))) {
                $key = $this->escapeshellarg($key);
            }
            $key = $prefix.$key;

            $values = $argument->getValues();

            if (empty($values)) {
                $cmd .= " $key";
                continue;
            }

            foreach ($values as $val) {
                $cmd .= " $key";
                $cmd .= ($this->flags & DONT_ADD_SPACE_BEFORE_VALUE) ? '' : ' ';
                if ($argument->willEscape() === true || ($argument->willEscape() === null && ($this->flags & ESCAPE))) {
                    $val = $this->escapeshellarg($val);
                }
                $cmd .= $val;
            }
        }

        return trim($cmd);
    }
628240
private function getCommandAliasesText(AbstractCommand $command): string
	{
		$text    = '';
		$aliases = $command->getAliases();

		if ($aliases)
		{
			$text = '[' . implode('|', $aliases) . '] ';
		}

		return $text;
	}
624924
public function completeCommand()
    {
        $arguments = array_slice($GLOBALS['argv'], 3);
        $position = (int)$arguments[0];

        $arguments = array_slice($arguments, 1);

        $count = count($arguments);

        $controller = null;
        if ($count > 1) {
            $controller = $arguments[1];
        }

        $command = null;
        if ($count > 2) {
            $command = $arguments[2];
            if ($command !== '' && $command[0] === '-') {
                $command = 'default';
            }
        }

        $previous = $position > 0 ? $arguments[$position - 1] : null;

        $current = isset($arguments[$position]) ? $arguments[$position] : '';

        if ($position === 1) {
            $words = $this->_getControllers();
        } elseif ($current !== '' && $current[0] === '-') {
            $words = $this->_getArgumentNames($controller, $command);
        } elseif ($position === 2) {
            $words = $this->_getCommands($controller);
        } else {
            $words = $this->_getArgumentValues($controller, $command, $previous);
        }

        $this->console->writeLn(implode(' ', $this->_filterWords($words, $current)));

        return 0;
    }
560960
public function getCommand()
    {
        return sprintf(
            "put %d %d %d %d",
            $this->_priority,
            $this->_delay,
            $this->_ttr,
            strlen($this->_message)
        );
    }
793693
public function cmdDeleteLanguage()
    {
        $id = $this->getParam(0);
        $all = $this->getParam('all');

        if (!isset($id) && empty($all)) {
            $this->errorAndExit($this->text('Invalid command'));
        }

        $result = false;

        if (isset($id)) {
            $result = $this->language->delete($id);
        } else if (!empty($all)) {

            $deleted = $count = 0;

            foreach ($this->language->getList(array('in_database' => true)) as $language) {
                $count++;
                $deleted += (int) $this->language->delete($language['code']);
            }

            $result = $count && $count == $deleted;
        }

        if (empty($result)) {
            $this->errorAndExit($this->text('Unexpected result'));
        }

        $this->output();
    }
17709
public function getCommand(): string
    {
        $port = $this->config->getPort();

        $java_bin = $this->config->getJavaBin();

        $jars = [];
        $classpaths = $this->config->getClasspaths();
        foreach ($classpaths as $classpath) {
            if (preg_match('/\*\.jar$/', $classpath)) {
                $directory = preg_replace('/\*\.jar$/', '', $classpath);
                $files = glob("$directory/*.jar");
                //foreach ($files as $file) {
                foreach ($files as $file) {
                    $jars[] = $file;
                }
                //}
            } else {
                $jars[] = $classpath;
            }
        }

        $jars[] = $this->config->getServerJar();
        $classpath = implode(':', $jars);
        $threads = $this->config->getThreads();

        $directives = ' -D' . implode(' -D', [
                    'php.java.bridge.daemon="false"',
                    "php.java.bridge.threads=$threads"
        ]);

        $command = sprintf(
            '%s -cp "%s" %s php.java.bridge.Standalone SERVLET:%d',
            $java_bin,
            $classpath,
            $directives,
            $port
        );

        return $command;
    }
224069
public function buildCommand()
    {
        $command = $this->command . ' >> ' . $this->_output . ' 2>&1 &';

        return $this->_user ? 'sudo -u ' . $this->_user . ' ' . $command : $command;
    }
917597
protected function compileCommand()
    {
        $output = ProcessUtils::escapeArgument($this->output);

        $redirect = $this->shouldAppendOutput ? ' >> ' : ' > ';

        if (! $this->runInBackground) {
            return $this->command .$redirect .$output .' 2>&1';
        }

        $delimiter = windows_os() ? '&' : ';';

        $phpBinary = ProcessUtils::escapeArgument(
            with(new PhpExecutableFinder)->find(false)
        );

        $forgeBinary = defined('FORGE_BINARY') ? ProcessUtils::escapeArgument(FORGE_BINARY) : 'forge';

        $finished = $phpBinary .' ' .$forgeBinary .' schedule:finish ' . ProcessUtils::escapeArgument($this->mutexName());

        return '(' .$this->command .$redirect .$output .' 2>&1 ' .$delimiter .' ' .$finished .') > '
            . ProcessUtils::escapeArgument($this->getDefaultOutput()) .' 2>&1 &';
    }