public function testOptionGroups() { ClearIce::addGroups(['group' => 'location', 'help' => 'Location options'], ['group' => 'testing', 'help' => 'Some testing options']); ClearIce::addOptions(array('short' => 'i', 'long' => 'input', 'has_value' => true, 'group' => 'location', 'help' => "specifies where the input files for the wiki are found."), array('short' => 'o', 'long' => 'output', 'has_value' => true, 'group' => 'location', "help" => "specifies where the wiki should be written to"), array('short' => 'v', 'long' => 'verbose', "help" => "displays detailed information about everything that happens"), array('short' => 'x', 'long' => 'create-default-index', 'has_value' => false, "help" => "creates a default index page which lists all the wiki pages in a sorted order"), array('short' => 'd', 'long' => 'some-very-long-option-indeed', 'has_value' => false, 'group' => 'testing', "help" => "an uneccesarily long option which is meant to to see if the wrapping of help lines actually works."), array('short' => 's', 'has_value' => false, 'group' => 'testing', "help" => "a short option only"), array('long' => 'lone-long-option', 'has_value' => false, 'group' => 'testing', "help" => "a long option only")); $helpMessage = ClearIce::getHelpMessage(); $this->assertEquals(file_get_contents('tests/data/help_groups.txt'), $helpMessage); }
$options = ClearIce::parse(); if (isset($options['verbose'])) { ClearIce::setOutputLevel($options['verbose']); } try { if (isset($options['__command__'])) { if (isset($options['home'])) { Yentu::setDefaultHome($options['home']); } $class = "\\yentu\\commands\\" . ucfirst($options['__command__']); unset($options['__command__']); Config::readPath(Yentu::getPath('config'), 'yentu'); $command = new $class(); $command->run($options); } else { ClearIce::output(ClearIce::getHelpMessage()); } } catch (\yentu\exceptions\CommandException $e) { ClearIce::resetOutputLevel(); ClearIce::error("Error! " . $e->getMessage() . "\n"); } catch (\ntentan\atiaa\exceptions\DatabaseDriverException $e) { ClearIce::resetOutputLevel(); ClearIce::error("Database driver failed: " . $e->getMessage() . "\n"); Yentu::reverseCommand($command); } catch (\yentu\exceptions\DatabaseManipulatorException $e) { ClearIce::resetOutputLevel(); ClearIce::error("Failed to perform database action: " . $e->getMessage() . "\n"); Yentu::reverseCommand($command); } catch (\ntentan\atiaa\DescriptionException $e) { ClearIce::resetOutputLevel(); ClearIce::error("Failed to perform database action: " . $e->getMessage() . "\n");
public function testMultipleUsage() { global $argv; $argv = array("test.php"); ClearIce::setUsage(array("[input] [options]..", "[output] [options]..")); ClearIce::setDescription("Simple Wiki version 1.0\nA sample or should I say dummy wiki app to help explain ClearIce. This app practically does nothing."); ClearIce::setFootnote("Hope you had a nice time learning about ClearIce. We're pretty sure your cli apps would no longer be boring to work with.\n\nReport bugs to bugs@clearice.tld"); ClearIce::addHelp(); $helpMessage = ClearIce::getHelpMessage(); $this->assertEquals(file_get_contents('tests/data/help_multi_usage.txt'), $helpMessage); }