From 36be91ea5d101a3baa2badec86c4cd179b05895a Mon Sep 17 00:00:00 2001 From: Carl Olsen Date: Tue, 16 Jul 2013 17:01:26 -0400 Subject: [PATCH] Update Option.php 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. --- src/Commando/Option.php | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/Commando/Option.php b/src/Commando/Option.php index 0774022..2f1cdf8 100644 --- a/src/Commando/Option.php +++ b/src/Commando/Option.php @@ -1,7 +1,7 @@ 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)) { @@ -285,21 +287,38 @@ public function getHelp() } } if (!$this->isBoolean()) { - $help .= ' ' . $color('')->underline(); + $help .= ' ' . $color->underline(''); } $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;