10000 Merge pull request #46 from sabl0r/argument_description · kler/getopt-php@26ee0cd · GitHub
[go: up one dir, main page]

Skip to content

Commit 26ee0cd

Browse files
committed
Merge pull request getopt-php#46 from sabl0r/argument_description
Add support for optional argument description
2 parents eb8f1dc + d103b49 commit 26ee0cd

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/Ulrichsg/Getopt/Argument.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class Argument
88
private $default;
99
/** @var callable */
1010
private $validation;
11+
/** @var string */
12+
private $description;
1113

1214
/**
1315
* Creates a new argument.
@@ -16,14 +18,15 @@ class Argument
1618
* @param callable|null $validation a validation function (optional)
1719
* @throws \InvalidArgumentException
1820
*/
19-
public function __construct($default = null, $validation = null)
21+
public function __construct($default = null, $validation = null, $description = "arg")
2022
{
2123
if (!is_null($default)) {
2224
$this->setDefaultValue($default);
2325
}
2426
if (!is_null($validation)) {
2527
$this->setValidation($validation);
2628
}
29+
$this->description = $description;
2730
}
2831

2932
/**
@@ -99,4 +102,14 @@ public function getDefaultValue()
99102
{
100103
return $this->default;
101104
}
105+
106+
/**
107+
* Retrieve the descriptopm
108+
*
109+
* @return string
110+
*/
111+
public function getDescription()
112+
{
113+
return $this->description;
114+
}
102115
}

src/Ulrichsg/Getopt/Getopt.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,10 @@ public function getHelpText($padding = 25)
225225
$mode = '';
226226
break;
227227
case self::REQUIRED_ARGUMENT:
228-
$mode = "<arg>";
228+
$mode = "<".$option->getArgument()->getDescription().">";
229229
break;
230230
case self::OPTIONAL_ARGUMENT:
231-
$mode = "[<arg>]";
231+
$mode = "[<".$option->getArgument()->getDescription().">]";
232232
break;
233233
}
234234
$short = ($option->short()) ? '-'.$option->short() : '';

0 commit comments

Comments
 (0)
0