Skip to content

Commit

Permalink
Make sure OPTIONS section in help is shown if the command takes argum…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
stuartherbert committed Apr 20, 2011
1 parent 84d5e77 commit 0080e7e
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/php/Phix_Project/PhixExtensions/CommandBase.php
Expand Up @@ -160,7 +160,7 @@ protected function showSwitchSummary(Context $context, $sortedSwitches)
protected function showOptions(Context $context, $sortedSwitches, $args)
{
// do we have any options to show?
if (count($sortedSwitches['allSwitches']) == 0)
if (count($sortedSwitches['allSwitches']) == 0 && count($args) == 0)
{
// no we do not
return;
Expand All @@ -171,7 +171,11 @@ protected function showOptions(Context $context, $sortedSwitches, $args)
$so->setIndent(0);
$so->outputLine(null, 'OPTIONS');
$so->addIndent(4);
$this->showSwitchDetails($context, $sortedSwitches);

if (count($sortedSwitches['allSwitches']) > 0)
{
$this->showSwitchDetails($context, $sortedSwitches);
}

if (count($args) > 0)
{
Expand Down
Expand Up @@ -69,6 +69,27 @@ public function getCommandDesc()
}
}

class DummyCommandWithNoSwitchesAndOneArg extends CommandBase
{
public function getCommandName()
{
return 'DummyCommand:withNoSwitchesAndOneArg';
}

public function getCommandDesc()
{
return 'A dummy command with only arguments to prove that CommandBase still does the right thing';
}

public function getCommandArgs()
{
return array
(
'<folder>' => '<folder> is a path to an existing folder, which you must have permission to write to.',
);
}
}

class DummyCommandWithSwitches extends CommandBase
{
public function getCommandName()
Expand Down Expand Up @@ -372,6 +393,59 @@ public function testDoesNotOutputOptionsSectionWhenNoSwitches()
* /home/stuarth/Devel/GWC/phix/src/tests/unit-tests/php/Phix_Project
/PhixExtensions/CommandBaseTest.php
EOS;

$this->assertEquals($expectedString, $stdOutOutput);
}

public function testDoesOutputOptionsSectionWhenNoSwitchesOnlyArgs()
{
// setup
$obj = new DummyCommandWithNoSwitchesAndOneArg();
$context = new Context();
$context->argvZero = 'phix';
$context->stdout = new DevString();
$context->stderr = new DevString();

// do the test
$obj->outputHelp($context);

// test the results
$stdOutOutput = $context->stdout->_getOutput();
$stdErrOutput = $context->stderr->_getOutput();

$this->assertEquals(0, strlen($stdErrOutput));
$this->assertNotEquals(0, strlen($stdOutOutput));

// var_dump($stdOutOutput);

// that just tells us we have some sort of output in
// the expected places
//
// do we have the _right_ output?
$expectedString = <<<EOS
NAME
phix DummyCommand:withNoSwitchesAndOneArg - A dummy command with only
arguments to prove that CommandBase still does the right thing
SYNOPSIS
phix DummyCommand:withNoSwitchesAndOneArg <folder>
OPTIONS
<folder>
<folder> is a path to an existing folder, which you must have
permission to write to.
IMPLEMENTATION
This command is implemented in the PHP class:
* Phix_Project\PhixExtensions\DummyCommandWithNoSwitchesAndOneArg
which is defined in the file:
* /home/stuarth/Devel/GWC/phix/src/tests/unit-tests/php/Phix_Project
/PhixExtensions/CommandBaseTest.php
EOS;

$this->assertEquals($expectedString, $stdOutOutput);
Expand Down

0 comments on commit 0080e7e

Please sign in to comment.