yii\console\controllers\HelpController::formatOptionHelp PHP Method

formatOptionHelp() protected method

Generates a well-formed string for an argument or option.
protected formatOptionHelp ( string $name, boolean $required, string $type, mixed $defaultValue, string $comment ) : string
$name string the name of the argument or option
$required boolean whether the argument is required
$type string the type of the option or argument
$defaultValue mixed the default value of the option or argument
$comment string comment about the option or argument
return string the formatted string for the argument or option
    protected function formatOptionHelp($name, $required, $type, $defaultValue, $comment)
    {
        $comment = trim($comment);
        $type = trim($type);
        if (strncmp($type, 'bool', 4) === 0) {
            $type = 'boolean, 0 or 1';
        }
        if ($defaultValue !== null && !is_array($defaultValue)) {
            if ($type === null) {
                $type = gettype($defaultValue);
            }
            if (is_bool($defaultValue)) {
                // show as integer to avoid confusion
                $defaultValue = (int) $defaultValue;
            }
            if (is_string($defaultValue)) {
                $defaultValue = "'" . $defaultValue . "'";
            } else {
                $defaultValue = var_export($defaultValue, true);
            }
            $doc = "{$type} (defaults to {$defaultValue})";
        } else {
            $doc = $type;
        }
        if ($doc === '') {
            $doc = $comment;
        } elseif ($comment !== '') {
            $doc .= "\n" . preg_replace('/^/m', '  ', $comment);
        }
        $name = $required ? "{$name} (required)" : $name;
        return $doc === '' ? $name : "{$name}: {$doc}";
    }