Skip to content

Commit e0d0b03

Browse files
committed
Display title if specified instead af a numeric index on missing required parameter error
1 parent bf0f579 commit e0d0b03

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/Commando/Command.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,16 @@ public function parse()
489489
// todo protect against duplicates caused by aliases
490490
foreach ($this->options as $option) {
491491
if (is_null($option->getValue()) && $option->isRequired()) {
492-
throw new \Exception(sprintf('Required %s %s must be specified',
493-
$option->getType() & Option::TYPE_NAMED ?
494-
'option' : 'argument', $option->getName()));
492+
$name = $option->getName();
493+
if ($option->getType() & Option::TYPE_NAMED) {
494+
$nature = 'option';
495+
} else {
496+
$nature = 'argument';
497+
if ($title = $option->getTitle()) {
498+
$name = $title;
499+
}
500+
}
501+
throw new \Exception(sprintf('Required %s %s must be specified', $nature, $name));
495502
}
496503
}
497504

src/Commando/Option.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,14 @@ public function getAliases()
320320
return $this->aliases;
321321
}
322322

323+
/**
324+
* @return string title of the option
325+
*/
326+
public function getTitle()
327+
{
328+
return $this->title;
329+
}
330+
323331
/**
324332
* Get the current set of this option's requirements
325333
* @return string[] List of required options

0 commit comments

Comments
 (0)