Skip to content

Commit 3bffa4e

Browse files
committed
feat: support add hidden flag options
1 parent 1242dd7 commit 3bffa4e

File tree

5 files changed

+48
-0
lines changed

5 files changed

+48
-0
lines changed

src/Concern/HelperRenderTrait.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ trait HelperRenderTrait
7070
*/
7171
protected $showTypeOnHelp = true;
7272

73+
/**
74+
* @var bool
75+
*/
76+
protected $showHiddenOpt = false;
77+
7378
/**
7479
* Will call it on before print help message
7580
*
@@ -287,6 +292,11 @@ protected function buildOptsForHelp(array $optDefines, bool $hasShortOpt): array
287292

288293
/** @var array|Option $opt {@see FlagsParser::DEFINE_ITEM} */
289294
foreach ($optDefines as $name => $opt) {
295+
// hidden option
296+
if ($this->showHiddenOpt === false && $opt['hidden']) {
297+
continue;
298+
}
299+
290300
$names = $opt['shorts'];
291301
/** @see Option support alias name. */
292302
if (isset($opt['alias']) && $opt['alias']) {
@@ -438,4 +448,12 @@ public function setBeforePrintHelp(callable $beforePrintHelp): void
438448
{
439449
$this->beforePrintHelp = $beforePrintHelp;
440450
}
451+
452+
/**
453+
* @param bool $showHiddenOpt
454+
*/
455+
public function setShowHiddenOpt(bool $showHiddenOpt): void
456+
{
457+
$this->showHiddenOpt = $showHiddenOpt;
458+
}
441459
}

src/Flag/Option.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ class Option extends AbstractFlag
4848
*/
4949
private $shortcut = '';
5050

51+
/**
52+
* @var bool
53+
*/
54+
private $hidden = false;
55+
5156
/**
5257
* @return bool
5358
*/
@@ -160,6 +165,22 @@ public function getHelpName(): string
160165
return implode(', ', $nodes);
161166
}
162167

168+
/**
169+
* @return bool
170+
*/
171+
public function isHidden(): bool
172+
{
173+
return $this->hidden;
174+
}
175+
176+
/**
177+
* @param bool $hidden
178+
*/
179+
public function setHidden(bool $hidden): void
180+
{
181+
$this->hidden = $hidden;
182+
}
183+
163184
/**
164185
* @return array
165186
*/

src/Flags.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,10 @@ public function getOptsHelpData(): array
10281028
{
10291029
$helpData = [];
10301030
foreach ($this->options as $name => $opt) {
1031+
if ($this->showHiddenOpt === false && $opt['hidden']) {
1032+
continue;
1033+
}
1034+
10311035
$names = $opt['shorts'];
10321036
$names[] = $name;
10331037

src/FlagsParser.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ abstract class FlagsParser implements ParserInterface
6161
'envVar' => '', // support read value from ENV var
6262
'default' => null,
6363
'shorts' => [], // only for option. ['a', 'b']
64+
'hidden' => false, // only for option
6465
// value validator
6566
'validator' => null,
6667
// 'category' => null

src/SFlags.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,10 @@ public function getOptsHelpData(): array
10311031
{
10321032
$helpData = [];
10331033
foreach ($this->optDefines as $name => $define) {
1034+
if ($this->showHiddenOpt === false && $define['hidden']) {
1035+
continue;
1036+
}
1037+
10341038
$names = $define['shorts'];
10351039
$names[] = $name;
10361040

0 commit comments

Comments
 (0)