Skip to content

Commit

Permalink
Update Option.php
Browse files Browse the repository at this point in the history
Added improved and more consistent styling. Title now displays for named and anonymous params (not just anonymous). "Required" is colored in red. The first line is now bold.
  • Loading branch information
unstoppablecarl committed Jul 16, 2013
1 parent d03e6e6 commit 36be91e
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/Commando/Option.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

namespace Commando;

use \Commando\Util\Terminal;
class Option
{
private
Expand Down Expand Up @@ -275,7 +275,9 @@ public function getHelp()
$color = new \Colors\Color();
$help = '';

if ($this->type & self::TYPE_NAMED) {
$isNamed = ($this->type & self::TYPE_NAMED);

if ($isNamed) {
$help .= PHP_EOL . (mb_strlen($this->name, 'UTF-8') === 1 ?
'-' : '--') . $this->name;
if (!empty($this->aliases)) {
Expand All @@ -285,21 +287,38 @@ public function getHelp()
}
}
if (!$this->isBoolean()) {
$help .= ' ' . $color('<argument>')->underline();
$help .= ' ' . $color->underline('<argument>');
}
$help .= PHP_EOL;
} else {
$help .= (empty($this->title) ? "arg {$this->name}" : $this->title) . PHP_EOL;
}

$description = $this->description;
// bold what has been displayed so far
$help = $color->bold($help);

$titleLine = '';
if($isNamed && $this->title) {
$titleLine .= $this->title . '.';
if ($this->isRequired()) {
$titleLine .= ' ';
}
}

if ($this->isRequired()) {
$description = 'Required. ' . $description;
$titleLine .= $color->red('Required.');
}

if($titleLine){
$titleLine .= ' ';
}
$description = $titleLine . $this->description;
if (!empty($description)) {
$help .= \Commando\Util\Terminal::wrap(
$this->title . $description, 5, 1);
$descriptionArray = explode(PHP_EOL, trim($description));
foreach($descriptionArray as $descriptionLine){
$help .= Terminal::wrap($descriptionLine, 5, 1) . PHP_EOL;
}

}

return $help;
Expand Down

0 comments on commit 36be91e

Please sign in to comment.