Skip to content

Commit 0360379

Browse files
committed
Address HelpScreen feedback
1 parent 1c5d5e5 commit 0360379

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/cli/arguments/HelpScreen.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ public function render() {
8181
array_push( $help, $this->_renderFlags() );
8282
array_push( $help, $this->_renderOptions() );
8383

84+
$help = array_filter( $help, function ( $v ) {
85+
return $v !== null && $v !== '';
86+
} );
87+
8488
return join( "\n\n", $help );
8589
}
8690

tests/Test_Arguments.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,29 @@ public function testParseWithMissingOptionsWithDefault($cliParams, $expectedValu
294294
public function testParseWithNoOptionsWithDefault($cliParams, $expectedValues) {
295295
$this->_testParse($cliParams, $expectedValues);
296296
}
297+
298+
public function testHelpScreenRender() {
299+
$args = new \cli\Arguments( $this->settings );
300+
$help = $args->getHelpScreen();
301+
302+
$output = $help->render();
303+
304+
// It should contain Flags and Options sections
305+
$this->assertStringContainsString( 'Flags', $output );
306+
$this->assertStringContainsString( 'Options', $output );
307+
308+
// Now test with ONLY flags
309+
$settings = array(
310+
'flags' => $this->flags,
311+
);
312+
$args = new \cli\Arguments( $settings );
313+
$help = $args->getHelpScreen();
314+
$output = $help->render();
315+
316+
$this->assertStringContainsString( 'Flags', $output );
317+
$this->assertStringNotContainsString( 'Options', $output );
318+
319+
// It should NOT have leading/trailing newlines or empty sections
320+
$this->assertSame( trim( $output ), $output, 'Output should not have leading/trailing whitespace' );
321+
}
297322
}

0 commit comments

Comments
 (0)