1: <?php
2:
3: /**
4: * interface for classes implementing a command line application subcommand
5: */
6: interface CLI_Command {
7:
8: /**
9: * name of subcommand
10: */
11: static function CLI_commandName();
12:
13: /**
14: * description of subcommand
15: */
16: static function CLI_commandDescription();
17:
18: /**
19: * will be applied to autogenerated command --help option
20: */
21: static function CLI_longHelp();
22:
23: /**
24: * initiate your Console_Commandline subcommand on variable $parser here
25: * @param Console_CommandLine $parser
26: */
27: static function CLI_getCommand(Console_CommandLine $parser);
28:
29: /**
30: * you may check for required options for your command here
31: * @param type $options
32: */
33: static function CLI_checkRequiredOpts(Console_CommandLine_Result $command);
34:
35: /**
36: * execute code according to the $result
37: * return true on success, return false to display help, throw Error to display Error Message
38: * @param Console_CommandLine_Result $command
39: */
40: static function CLI_execute(Console_CommandLine_Result $command, Console_CommandLine $parser);
41: }
42:
43:
44: require_once 'Console/CommandLine/Action.php';
45:
46: class Console_CommandLine_Action_ExtendedHelp extends Console_CommandLine_Action {
47:
48: public function execute($value = false, $params = array()) {
49: $helpstr = $this->parser->renderer->usage();
50: if (isset($params['class']) && class_exists($params['class']))
51: $helpstr.=call_user_func(array($params['class'], 'CLI_longHelp')) . "\n";
52: $this->parser->outputter->stdout($helpstr);
53: exit(0);
54: }
55:
56: }
57:
58: //overwrite CommandLine Help function to provide longHelp support... ouch!
59: Console_CommandLine::$actions['Help'] = array('Console_CommandLine_Action_ExtendedHelp', false);
60:
61:
62: ?>
63: