/** * Builds an object for parsing the command line arguments * * @return \r8\CLI\Command */ public static function getArgParser() { $cmd = new \r8\CLI\Command('vocab', 'PHP documentation generator'); $pathFilter = new \r8\Filter\Chain(new \r8\Filter\Printable(), new \r8\Curry\Call('trim')); $cmd->addArg(new \r8\CLI\Arg\One('Output Directory', $pathFilter, new \r8\Validator\All(\r8(new \r8\Validator\NotEmpty())->addError('Output directory must not be empty'), new \r8\Validator\Callback(function ($dir) { return is_file($dir) ? 'Path must not be an existing file: ' . $dir : NULL; })))); $inputValidator = new \r8\Validator\All(\r8(new \r8\Validator\NotEmpty())->addError('Input path must not be empty'), new \r8\Validator\Callback(function ($path) { return file_exists($path) ? NULL : 'Path does not exist: ' . $path; })); $cmd->addArg(new \r8\CLI\Arg\One('Input Path', $pathFilter, $inputValidator)); $cmd->addArg(new \r8\CLI\Arg\Many('Input Path', $pathFilter, $inputValidator)); // A command form for viewing help/version info $info = new \r8\CLI\Form(); $cmd->addForm($info); $info->addOption(\r8(new \r8\CLI\Option('v', 'Outputs version information'))->addFlag('version')); $info->addOption(\r8(new \r8\CLI\Option('h', 'Displays the help screen'))->addFlag('help')); return $cmd; }
public function testGetHelp_LongDescription() { $command = new \r8\CLI\Command('cmd', 'A particularly long description of this command that will need ' . 'to be wrapped because of its length'); $this->assertSame("USAGE:\n" . " cmd\n\n" . "DESCRIPTION:\n" . " A particularly long description of this command that will need to be wrapped\n" . " because of its length\n\n", $command->getHelp()); }