Airship\Hangar\Commands\Help::helpMenu PHP Method

helpMenu() public method

Display the main help menu
public helpMenu ( ) : void
return void
    public function helpMenu()
    {
        $essential = [];
        $coms = [];
        $columns = [8, 4, 11];
        foreach ($this->commands as $i => $name) {
            if (\strlen($i) > $columns[0]) {
                $columns[0] = \strlen($i);
            }
            if ($name === 'Help') {
                if (\strlen($this->name) > $columns[1]) {
                    $columns[1] = \strlen($this->name);
                }
                if (\strlen($this->description) > $columns[2]) {
                    $columns[2] = \strlen($this->description);
                }
                $coms[$i] = ['name' => $this->name, 'description' => $this->description, 'display' => $this->display];
            } else {
                $com = $this->getCommandObject($name);
                if (\strlen($com->name) > $columns[1]) {
                    $columns[1] = \strlen($com->name);
                }
                // $descr is just for length calculations
                // $details is with the tag
                $descr = $com->description;
                $details = $com->description;
                if (!empty($com->tag['text'])) {
                    $descr = '[' . $com->tag['text'] . '] ' . $descr;
                    $details = $this->c[$com->tag['color']] . '[' . $com->tag['text'] . ']' . $this->c[''] . ' ' . $com->description;
                }
                if (\strlen($descr) > $columns[2]) {
                    $columns[2] = \strlen($descr);
                }
                if ($com->essential) {
                    $essential[$i] = ['name' => $com->name, 'description' => $details, 'display' => $com->display];
                }
                $coms[$i] = ['name' => $com->name, 'description' => $details, 'display' => $com->display];
                unset($com);
            }
        }
        \uasort($essential, [$this, 'sortCommands']);
        \uasort($coms, [$this, 'sortCommands']);
        $width = $this->getScreenSize()['width'];
        // $desiredWidth = array_sum($columns) + (3 * self::TAB_SIZE);
        $wrap = $width - $columns[1] - $columns[0] - 3 * self::TAB_SIZE - 1;
        // Prevent wrapping because of newline characters
        --$columns[2];
        $repeatPad = \str_repeat(' ', $columns[0] + $columns[1] + 3 * self::TAB_SIZE);
        $TAB = \str_repeat(' ', self::TAB_SIZE);
        $HTAB = \str_repeat(' ', (int) ceil(self::TAB_SIZE / 2));
        $header = $this->c['blue'] . $TAB . \str_pad('Command', $columns[0], ' ', STR_PAD_RIGHT) . $TAB . \str_pad('Name', $columns[1], ' ', STR_PAD_RIGHT) . $TAB . 'Description' . $this->c[''] . "\n" . $TAB . \str_repeat('=', $width - self::TAB_SIZE - 1) . "\n";
        echo $this->c[''], $HTAB, "How to use one of the commands in the table below:\n";
        echo $TAB, $this->c['cyan'], "hangar [command]", $this->c[''], "\n";
        echo $TAB, $HTAB, "Run the command.";
        echo "\n\n";
        echo $TAB, $this->c['cyan'] . "hangar help [command]", $this->c[''], "\n";
        echo $TAB, $HTAB, "Display usage information for a specific command.";
        echo "\n\n";
        echo $HTAB, $this->label['topCommands'], "\n";
        echo $header;
        $newline = false;
        foreach ($essential as $k => $com) {
            if ($newline) {
                echo "\n", $TAB, \str_repeat('-', $width - self::TAB_SIZE - 1), "\n";
            }
            echo $TAB;
            echo $this->c['yellow'] . \str_pad($k, $columns[0], ' ', STR_PAD_RIGHT) . $this->c[''];
            echo $TAB;
            echo \str_pad($com['name'], $columns[1], ' ', STR_PAD_RIGHT);
            echo $TAB;
            echo \wordwrap($com['description'], $wrap, "\n" . $repeatPad, true);
            $newline = true;
        }
        if (!$this->showAll) {
            echo "\n\n", $HTAB, 'To view all of the available commands, run this command: ';
            echo $this->c['cyan'], 'hangar help', $this->c[''];
            return;
        }
        echo "\n\n", $HTAB, $this->label['allCommands'], "\n";
        echo $header;
        $nl = false;
        foreach ($coms as $k => $com) {
            if ($nl) {
                echo "\n", $TAB, \str_repeat('-', $width - self::TAB_SIZE - 1), "\n";
            }
            echo $TAB;
            echo "", \str_pad($k, $columns[0], ' ', STR_PAD_RIGHT), "";
            echo $TAB;
            echo \str_pad($com['name'], $columns[1], ' ', STR_PAD_RIGHT);
            echo $TAB;
            echo \wordwrap($com['description'], $wrap, "\n" . $repeatPad, true);
            $nl = true;
        }
    }