Skip to content

Commit c39be44

Browse files
committed
Fix description block excessive padding in HelpGenerator.
1 parent 8ac4789 commit c39be44

4 files changed

Lines changed: 29 additions & 20 deletions

File tree

docs/changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ This change log references the repository changes and releases, which respect [s
1313
in your production classes under 'dev' environment (when you call `composer install` without `--no-dev` option),
1414
you will get "Class 'XXX' not found in ..." error.
1515
Previously there was no error, until you install composer packages with `--no-dev` flag.
16+
1. Fixed scripts main description block - stopped counting symbols in space-only lines.
17+
Previously it caused too much padding for descriptions with too short space-only lines.
1618

1719
## v2.0.0
1820

src/Parametizer/Config/HelpGenerator.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,12 @@ public function getDescriptionBlock(): string {
123123
// 3. Determine the minimum heading spaces count in all lines of description.
124124
$descriptionLines = explode(PHP_EOL, $description);
125125
$minHeadingSpacesCount = null;
126-
foreach ($descriptionLines as $line) {
127-
// Do not count empty lines:
128-
if (!$line) {
126+
foreach ($descriptionLines as $lineIndex => $line) {
127+
// 4. Trim space-only lines.
128+
// Ignore empty and space-only lines:
129+
if (!trim($line)) {
130+
$descriptionLines[$lineIndex] = '';
131+
129132
continue;
130133
}
131134

@@ -135,19 +138,14 @@ public function getDescriptionBlock(): string {
135138
}
136139
}
137140

138-
// 4. Delete that many heading spaces from each line.
141+
// 5. Delete that many heading spaces from each line.
139142
if ($minHeadingSpacesCount) {
140-
foreach ($descriptionLines as &$line) {
141-
// 5. Trim space-only lines.
142-
if (!trim($line)) {
143-
$line = '';
144-
}
145-
143+
foreach ($descriptionLines as $lineIndex => $line) {
146144
if (!$line) {
147145
continue;
148146
}
149147

150-
$line = mb_substr($line, $minHeadingSpacesCount);
148+
$descriptionLines[$lineIndex] = mb_substr($line, $minHeadingSpacesCount);
151149
}
152150
unset($line);
153151

tests/Tests/Parametizer/HelpGenerator/HelpGeneratorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class HelpGeneratorTest extends TestCaseAbstract {
2323
*
2424
* @see HelpGenerator::getFullHelp()
2525
* @see HelpGenerator::getParamsBlock()
26+
* @see HelpGenerator::getDescriptionBlock()
2627
*/
2728
public function testScriptHelp(): void {
2829
assertSame(

tests/Tests/Parametizer/HelpGenerator/scripts/lots-of-params.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,24 @@
77
require_once __DIR__ . '/../../../init-console.php';
88

99
Parametizer::newConfig(throwOnException: true)
10+
/*
11+
* There is excessive padding.
12+
* Also pay attention at the blank line with 4 spaces under the first paragraph: in previous version it caused
13+
* the whole help block to be shown as is with such a huge padding. The point is that the length of this exact
14+
* space-line negatively affected the whole block minimum padding. However now it should be ignored at all,
15+
* so eventually there should be correct padding for the whole block.
16+
*/
1017
->description('
11-
Here is a very very very very long description.
12-
So long that multiple lines are needed.
13-
14-
And there is more than that! Here is a list with padding, which should be outputted the same way in a terminal:
15-
1. Start with this step.
16-
2. Proceed with doing this thing.
17-
3. Finally finish by doing this stuff.
18-
19-
HERE IS SOME MORE PADDED TEXT
18+
Here is a very very very very long description.
19+
So long that multiple lines are needed.
20+
21+
And there is more than that! Here is a list with padding, which should be outputted the same way '
22+
. 'in a terminal:
23+
1. Start with this step.
24+
2. Proceed with doing this thing.
25+
3. Finally finish by doing this stuff.
26+
27+
HERE IS SOME MORE PADDED TEXT
2028
2129
2230

0 commit comments

Comments
 (0)