public static function showSwitchLongDetails(Context $context, DefinedSwitch $switch) { $so = $context->stdout; $shortOrLongSwitches = $switch->getHumanReadableSwitchList(); $append = false; foreach ($shortOrLongSwitches as $shortOrLongSwitch) { if ($append) { $so->output(null, ' | '); } $append = true; $so->output($context->switchStyle, $shortOrLongSwitch); // is there an argument? if ($switch->testHasArgument()) { if ($shortOrLongSwitch[1] == '-') { $so->output(null, '='); } else { $so->output(null, ' '); } $so->output($context->argStyle, $switch->arg->name); } } $so->outputLine(null, ''); $so->addIndent(4); $so->outputLine(null, $switch->desc); if (isset($switch->longdesc)) { $so->outputBlankLine(); $so->outputLine(null, $switch->longdesc); } // output the default argument, if it is set if ($switch->testHasArgument() && isset($switch->arg->defaultValue)) { $so->outputBlankLine(); $so->output(null, 'The default value for '); $so->output($context->argStyle, $switch->arg->name); $so->output(null, ' is: '); $so->outputLine($context->exampleStyle, $switch->arg->defaultValue); } $so->addIndent(-4); $so->outputBlankLine(); }
public function testCanAutoGenerateAHumanReadableDesc() { $obj = new DefinedSwitch('include', 'add a folder to load commands from'); $obj->setLongDesc("Phix finds all of its commands by searching PHP's include_path for files with " . "the file extension '.Phix.php'. If you want to Phix to look in other folders " . "without having to add them to PHP's include_path, use --include to tell Phix " . "to look in these folders." . \PHP_EOL . \PHP_EOL . "Phix expects '<path>' to point to a folder that conforms to the PSR0 standard " . "for autoloaders." . \PHP_EOL . \PHP_EOL . "For example, if your command is the class '\\Me\\Tools\\ScheduledTask', Phix would " . "expect to autoload this class from the 'Me/Tools/ScheduledTask.Phix.php' file." . \PHP_EOL . \PHP_EOL . "If your class lives in the './myApp/lib/Me/Tools' folder, you would call Phix " . "with 'Phix --include=./myApp/lib'")->setWithShortSwitch('I')->setWithLongSwitch('include')->setWithRequiredArg('<path>', 'The path to the folder to include')->setArgValidator(new MustBeValidPath())->setSwitchIsRepeatable(); $desc = $obj->getHumanReadableSwitchList(); $expectedArray = array("-I" => "-I", "--include" => "--include"); $this->assertEquals($expectedArray, $desc); }
public function testValidationReturnsArrayOfErrorsIfValidationsFail() { // first, we need a definition $name = 'Fred'; $desc = 'Fred is a jolly fellow'; $def = new DefinedSwitch($name, $desc); $this->assertEquals($def->name, $name); $this->assertEquals($def->desc, $desc); $def->setWithRequiredArg('harry', 'harry does love his food'); $def->setArgValidator(new MustBeInteger()); // now, we use the definition to create // the ParsedSwitch $obj = new ParsedSwitch($def); // add a value for the validator $obj->addValue('trout'); // run the validation $result = $obj->validateValues(); $this->assertTrue(is_array($result)); $this->assertEquals(1, count($result)); }