mirror of
https://github.com/n3w/helpers-cli-input.git
synced 2025-12-19 12:43:23 +00:00
Added getDisplayName() method to standardise how the name of an InputTypeInterface class wants to display it's name
This commit is contained in:
parent
b89f2a6008
commit
4117ed266c
4 changed files with 28 additions and 12 deletions
|
|
@ -17,4 +17,6 @@ interface InputTypeInterface
|
||||||
|
|
||||||
public function getType(): string;
|
public function getType(): string;
|
||||||
public function respondsTo(string $name): bool;
|
public function respondsTo(string $name): bool;
|
||||||
|
public function __toString(): string;
|
||||||
|
public function getDisplayName(): string;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,11 @@ class Argument extends Input\AbstractInputType
|
||||||
parent::__construct($name, $flags, $description, $validator, $default);
|
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.....
|
// MAGIC VALUES!!! OH MY.....
|
||||||
$padCharacter = ' ';
|
$padCharacter = ' ';
|
||||||
|
|
@ -53,7 +57,7 @@ class Argument extends Input\AbstractInputType
|
||||||
);
|
);
|
||||||
|
|
||||||
$first = Strings\mb_str_pad(
|
$first = Strings\mb_str_pad(
|
||||||
strtoupper($this->name()).str_repeat($padCharacter, $argumentNameMinimumPaddingWidth),
|
$this->getDisplayName().str_repeat($padCharacter, $argumentNameMinimumPaddingWidth),
|
||||||
$argumentNamePaddedWidth,
|
$argumentNamePaddedWidth,
|
||||||
$padCharacter
|
$padCharacter
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,18 @@ class LongOption extends Input\AbstractInputType
|
||||||
return ($name == $this->name || $name == $this->short);
|
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.....
|
// MAGIC VALUES!!! OH MY.....
|
||||||
$padCharacter = ' ';
|
$padCharacter = ' ';
|
||||||
|
|
@ -51,10 +62,7 @@ class LongOption extends Input\AbstractInputType
|
||||||
STR_PAD_LEFT
|
STR_PAD_LEFT
|
||||||
);
|
);
|
||||||
|
|
||||||
$short = null !== $this->short() ? '-'.$this->short() : null;
|
$long = $this->getDisplayName();
|
||||||
$long = null;
|
|
||||||
|
|
||||||
$long = '--'.$this->name();
|
|
||||||
if (Flags\is_flag_set($this->flags(), self::FLAG_VALUE_REQUIRED)) {
|
if (Flags\is_flag_set($this->flags(), self::FLAG_VALUE_REQUIRED)) {
|
||||||
$long .= '=VALUE';
|
$long .= '=VALUE';
|
||||||
} elseif (Flags\is_flag_set($this->flags(), self::FLAG_VALUE_OPTIONAL)) {
|
} 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(
|
$first = Strings\mb_str_pad(
|
||||||
(null !== $short ? "{$short}, " : '').$long, // -O, --LONG,
|
$long, // -O, --LONG,
|
||||||
$optionNamePaddedWidth,
|
$optionNamePaddedWidth,
|
||||||
$padCharacter
|
$padCharacter
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,11 @@ use pointybeard\Helpers\Cli\Input;
|
||||||
|
|
||||||
class Option extends Input\AbstractInputType
|
class Option extends Input\AbstractInputType
|
||||||
{
|
{
|
||||||
public function __toString()
|
public function getDisplayName(): string {
|
||||||
|
return '-'.$this->name();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
// MAGIC VALUES!!! OH MY.....
|
// MAGIC VALUES!!! OH MY.....
|
||||||
$padCharacter = ' ';
|
$padCharacter = ' ';
|
||||||
|
|
@ -38,10 +42,8 @@ class Option extends Input\AbstractInputType
|
||||||
STR_PAD_LEFT
|
STR_PAD_LEFT
|
||||||
);
|
);
|
||||||
|
|
||||||
$short = '-'.$this->name();
|
|
||||||
|
|
||||||
$first = Strings\mb_str_pad(
|
$first = Strings\mb_str_pad(
|
||||||
$short,
|
$this->getDisplayName(),
|
||||||
$optionNamePaddedWidth,
|
$optionNamePaddedWidth,
|
||||||
$padCharacter
|
$padCharacter
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue