diff --git a/src/Input/Interfaces/InputTypeInterface.php b/src/Input/Interfaces/InputTypeInterface.php index e61d304..92efb34 100644 --- a/src/Input/Interfaces/InputTypeInterface.php +++ b/src/Input/Interfaces/InputTypeInterface.php @@ -17,4 +17,6 @@ interface InputTypeInterface public function getType(): string; public function respondsTo(string $name): bool; + public function __toString(): string; + public function getDisplayName(): string; } diff --git a/src/Input/Types/Argument.php b/src/Input/Types/Argument.php index 3ada5b9..21a9a5d 100644 --- a/src/Input/Types/Argument.php +++ b/src/Input/Types/Argument.php @@ -25,7 +25,11 @@ class Argument extends Input\AbstractInputType parent::__construct($name, $flags, $description, $validator, $default); } - public function __toString() + public function getDisplayName(): string { + return strtoupper($this->name()); + } + + public function __toString(): string { // MAGIC VALUES!!! OH MY..... $padCharacter = ' '; @@ -53,7 +57,7 @@ class Argument extends Input\AbstractInputType ); $first = Strings\mb_str_pad( - strtoupper($this->name()).str_repeat($padCharacter, $argumentNameMinimumPaddingWidth), + $this->getDisplayName().str_repeat($padCharacter, $argumentNameMinimumPaddingWidth), $argumentNamePaddedWidth, $padCharacter ); diff --git a/src/Input/Types/LongOption.php b/src/Input/Types/LongOption.php index 8aae031..7d9af5b 100644 --- a/src/Input/Types/LongOption.php +++ b/src/Input/Types/LongOption.php @@ -24,7 +24,18 @@ class LongOption extends Input\AbstractInputType return ($name == $this->name || $name == $this->short); } - public function __toString() + public function getDisplayName(): string { + + $short = + null !== $this->short() + ? '-'.$this->short().', ' + : null + ; + + return sprintf("%s--%s", $short, $this->name()); + } + + public function __toString(): string { // MAGIC VALUES!!! OH MY..... $padCharacter = ' '; @@ -51,10 +62,7 @@ class LongOption extends Input\AbstractInputType STR_PAD_LEFT ); - $short = null !== $this->short() ? '-'.$this->short() : null; - $long = null; - - $long = '--'.$this->name(); + $long = $this->getDisplayName(); if (Flags\is_flag_set($this->flags(), self::FLAG_VALUE_REQUIRED)) { $long .= '=VALUE'; } elseif (Flags\is_flag_set($this->flags(), self::FLAG_VALUE_OPTIONAL)) { @@ -62,7 +70,7 @@ class LongOption extends Input\AbstractInputType } $first = Strings\mb_str_pad( - (null !== $short ? "{$short}, " : '').$long, // -O, --LONG, + $long, // -O, --LONG, $optionNamePaddedWidth, $padCharacter ); diff --git a/src/Input/Types/Option.php b/src/Input/Types/Option.php index 951caf4..2a193e3 100644 --- a/src/Input/Types/Option.php +++ b/src/Input/Types/Option.php @@ -11,7 +11,11 @@ use pointybeard\Helpers\Cli\Input; class Option extends Input\AbstractInputType { - public function __toString() + public function getDisplayName(): string { + return '-'.$this->name(); + } + + public function __toString(): string { // MAGIC VALUES!!! OH MY..... $padCharacter = ' '; @@ -38,10 +42,8 @@ class Option extends Input\AbstractInputType STR_PAD_LEFT ); - $short = '-'.$this->name(); - $first = Strings\mb_str_pad( - $short, + $this->getDisplayName(), $optionNamePaddedWidth, $padCharacter );