-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathHelpRenderer.php
More file actions
103 lines (78 loc) · 2.99 KB
/
HelpRenderer.php
File metadata and controls
103 lines (78 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
declare(strict_types=1);
/*
* This file is part of MMLC - ModifiedModuleLoaderClient.
*
* (c) Robin Wieschendorf <mail@robinwieschendorf.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace RobinTheHood\ModifiedModuleLoaderClient\Cli;
class HelpRenderer
{
private const INDENT = ' ';
private string $description = '';
private array $arguments = array();
public function setDescription(string $description): void
{
$this->description = $description;
}
public function addArgument(string $section, string $name, string $description, int $pad = 20)
{
$this->arguments[$section][$name] = $description;
}
public function getRender(): string
{
$render = '';
$render .= $this->getDescription();
$render .= $this->getArguments();
$render .= $this->getOptions();
return $render;
}
private function getDescription(): string
{
if (empty($this->arguments['description'])) {
return '';
}
$items = \array_keys($this->arguments['description']);
$padding = TextRenderer::getPadding($items);
$description = \PHP_EOL;
$description .= TextRenderer::color('Description', TextRenderer::COLOR_YELLOW) . \PHP_EOL;
$description .= self::INDENT . $this->description . \PHP_EOL . \PHP_EOL;
foreach ($this->arguments['description'] as $argument => $argumentDescription) {
$name = self::INDENT . TextRenderer::rightPad($argument, $padding);
$text = TextRenderer::color($name, TextRenderer::COLOR_GREEN) . $argumentDescription . \PHP_EOL;
$description .= $text;
}
return $description;
}
private function getArguments(): string
{
if (empty($this->arguments['arguments'])) {
return '';
}
$items = \array_keys($this->arguments['arguments']);
$padding = TextRenderer::getPadding($items);
$arguments = \PHP_EOL;
$arguments .= TextRenderer::color('Arguments', TextRenderer::COLOR_YELLOW) . \PHP_EOL;
foreach ($this->arguments['arguments'] as $argumentName => $argumentDescription) {
$arguments .= self::INDENT . TextRenderer::rightPad($argumentName, $padding) . $argumentDescription . \PHP_EOL;
}
return $arguments;
}
private function getOptions(): string
{
if (empty($this->arguments['options'])) {
return '';
}
$items = \array_keys($this->arguments['options']);
$padding = TextRenderer::getPadding($items);
$arguments = \PHP_EOL;
$arguments .= TextRenderer::color('Options', TextRenderer::COLOR_YELLOW) . \PHP_EOL;
foreach ($this->arguments['options'] as $argument => $description) {
$arguments .= self::INDENT . TextRenderer::rightPad($argument, $padding) . $description . \PHP_EOL;
}
return $arguments;
}
}