Skip to content

Commit

Permalink
Merge pull request #12 from unstoppablecarl/master
Browse files Browse the repository at this point in the history
Improved and more consistent styling to --help
  • Loading branch information
nategood committed Aug 1, 2013
2 parents d03e6e6 + 36be91e commit a513dc7
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 a513dc7

Please sign in to comment.