3 * Handles command line arguments.
\r
5 * Be careful the source has not been tested yet, it's probably very buggy.
\r
6 * Any help and comments are welcome...
\r
8 * @author Ulf Wendel <ulf@redsys.de>
\r
9 * @version $Id: PhpdocArgvHandler.php,v 1.2 2000/12/03 20:30:42 uw Exp $
\r
11 class PhpdocArgvHandler extends PhpdocObject {
\r
14 * Message explaining the usage of phpdoc on the command line.
\r
16 * Actually it's not the message itself but an array containing
\r
17 * the instructions. The array is indexed by the command line option e.g. "-h".
\r
18 * The array values hold a short message describing the usage of the option.
\r
23 var $COMMANDS = array(
\r
24 "-f filename [, filename]" => "name of files to parse",
\r
25 "-d directory" => "name of a directory to parse",
\r
26 "-p path" => "path of the files",
\r
27 "-t target" => "path where to save the generated files, default is the current path",
\r
28 "-h" => "show this help message"
\r
33 * Handle the command line values
\r
35 * handleArgv() looks for command line values and
\r
36 * interprets them. If there're unknown command it prints
\r
37 * a message and calls die()
\r
39 function handleArgv() {
\r
40 global $argv, $argc;
\r
42 // the first argv is the name of the script,
\r
43 // so there must be at least another one
\r
45 $error = "\n\nCould not understand your request.\n\n";
\r
46 $error.= $this->getArgvHelpMessage();
\r
56 // skip the fist, it's the name of the php script
\r
59 while (list($k, $arg)=each($argv)) {
\r
61 if ("-"!=substr($arg, 0, 1))
\r
64 $cmd = substr($arg, 1, 2);
\r
65 $value = trim(substr($arg, 3));
\r
67 // all command line options except -h require values
\r
68 if (""==$value && "h"!=$cmd) {
\r
70 "msg" => sprintf("-%s: no value found", trim($cmd)),
\r
73 // skip this command
\r
79 $files = explode(",", substr($arg, 3));
\r
80 $this->setFiles($files);
\r
85 $this->setDirectory($value);
\r
90 $this->setPath($value);
\r
95 $this->setTarget($value);
\r
104 $errors[]="unknown command: '$arg'";
\r
110 // are there enough informations to start work?
\r
111 $errors = $this->checkStatus($errors);
\r
113 // check for errors and die() if neccessary
\r
114 if (count($errors)>0) {
\r
115 $error = "\n\nCould not understand your request.\n\n";
\r
117 while (list($k, $data)=each($errors))
\r
118 $error.=$data["msg"]."\n";
\r
120 $error.= $this->getArgvHelpMessage();
\r
125 // no errors, but no recognized commands? die() if neccessary
\r
126 if (0==$commands) {
\r
127 $error = "\n\nCould not understand your request.\n\n";
\r
128 $error.= $this->getArgvHelpMessage();
\r
133 // YEAH everything is fine, we can start working!
\r
135 } // end func handleArgv
\r
138 * Returns the current help message of phpdoc
\r
140 * The message is not HTML formated, it could be shown
\r
141 * on the command line.
\r
144 * @return string $help_msg Some instructions on available command line options
\r
145 * @see handleArgv(), $COMMANDS
\r
147 function getArgvHelpMessage() {
\r
151 // generate the message from the COMMAND array
\r
152 reset($this->COMMANDS);
\r
153 while (list($param, $explanation)=each($this->COMMANDS))
\r
154 $help_msg.= sprintf("%-28s%s\n", $param, $explanation);
\r
156 $help_msg.="\nFurter information can be found in the documentation.\n";
\r
158 } // end func getArgvHelpMessage
\r
160 } // end class PhpdocArgvHandler
\r