Example #1
0
    public function testHelpDescriptionGroups()
    {
        $this->parser->setDescription("This is the program description for %prog.  %prog has " . "an option group as well as single options.");
        $group = new Horde_Argv_OptionGroup($this->parser, "Dangerous Options", "Caution: use of these options is at your own risk.  " . "It is believed that some of them bite.");
        $group->addOption("-g", array('action' => "store_true", 'help' => "Group option."));
        $this->parser->addOptionGroup($group);
        $expect = 'Usage: bar.php [options]

This is the program description for bar.php.  bar.php has an option group as
well as single options.

Options:
  -a APPLE           throw APPLEs at basket
  -b NUM, --boo=NUM  shout "boo!" NUM times (in order to frighten away all the
                     evil spirits that cause trouble and mayhem)
  --foo=FOO          store FOO in the foo list for later fooing
  -h, --help         show this help message and exit

  Dangerous Options:
    Caution: use of these options is at your own risk.  It is believed
    that some of them bite.

    -g               Group option.
';
        $this->assertHelpEquals($expect);
        $this->parser->epilog = "Please report bugs to /dev/null.";
        $this->assertHelpEquals($expect . "\nPlease report bugs to /dev/null.\n");
    }
Example #2
0
 /**
  * Create the parser for command line arguments.
  *
  * @return Horde_Argv_Parser The parser.
  */
 public function createParser()
 {
     $parser_class = $this->getParserClass();
     $parser = new $parser_class(array('usage' => '%prog ' . $this->getUsage()));
     foreach ($this->getModules() as $module_name) {
         $module = $this->getProvider()->getModule($module_name);
         foreach ($module->getBaseOptions() as $option) {
             $parser->addOption($option);
         }
         if ($module->hasOptionGroup()) {
             $group = new Horde_Argv_OptionGroup($parser, $module->getOptionGroupTitle(), $module->getOptionGroupDescription());
             foreach ($module->getOptionGroupOptions() as $option) {
                 $group->addOption($option);
             }
             $parser->addOptionGroup($group);
         }
     }
     return $parser;
 }