+++ /dev/null
-<?php\r
-/**\r
-* Handles command line arguments.\r
-*\r
-* Be careful the source has not been tested yet, it's probably very buggy.\r
-* Any help and comments are welcome...\r
-*\r
-* @author Ulf Wendel <ulf@redsys.de>\r
-* @version $Id: PhpdocArgvHandler.php,v 1.2 2000/12/03 20:30:42 uw Exp $\r
-*/\r
-class PhpdocArgvHandler extends PhpdocObject {\r
- \r
- /**\r
- * Message explaining the usage of phpdoc on the command line.\r
- * \r
- * Actually it's not the message itself but an array containing\r
- * the instructions. The array is indexed by the command line option e.g. "-h".\r
- * The array values hold a short message describing the usage of the option.\r
- * \r
- * @var array\r
- * @access private\r
- */\r
- var $COMMANDS = array(\r
- "-f filename [, filename]" => "name of files to parse",\r
- "-d directory" => "name of a directory to parse",\r
- "-p path" => "path of the files",\r
- "-t target" => "path where to save the generated files, default is the current path",\r
- "-h" => "show this help message"\r
- );\r
- \r
- \r
- /**\r
- * Handle the command line values\r
- * \r
- * handleArgv() looks for command line values and \r
- * interprets them. If there're unknown command it prints\r
- * a message and calls die()\r
- */ \r
- function handleArgv() {\r
- global $argv, $argc;\r
- \r
- // the first argv is the name of the script,\r
- // so there must be at least another one\r
- if ($argc<2) {\r
- $error = "\n\nCould not understand your request.\n\n";\r
- $error.= $this->getArgvHelpMessage();\r
- print $error;\r
- die();\r
- }\r
- \r
- $commands = 0;\r
- $errors = array();\r
- \r
- reset($argv);\r
- \r
- // skip the fist, it's the name of the php script\r
- next($argv);\r
- \r
- while (list($k, $arg)=each($argv)) {\r
- // valid command?\r
- if ("-"!=substr($arg, 0, 1))\r
- continue;\r
- \r
- $cmd = substr($arg, 1, 2); \r
- $value = trim(substr($arg, 3));\r
- \r
- // all command line options except -h require values\r
- if (""==$value && "h"!=$cmd) {\r
- $errors[] = array( \r
- "msg" => sprintf("-%s: no value found", trim($cmd)),\r
- "type" => "argv"\r
- );\r
- // skip this command\r
- continue;\r
- }\r
- \r
- switch ($cmd) {\r
- case "f ":\r
- $files = explode(",", substr($arg, 3));\r
- $this->setFiles($files);\r
- $commands++;\r
- break;\r
- \r
- case "d ":\r
- $this->setDirectory($value);\r
- $commands++;\r
- break;\r
- \r
- case "p ":\r
- $this->setPath($value);\r
- $commands++;\r
- break;\r
- \r
- case "t ":\r
- $this->setTarget($value);\r
- $commands++;\r
- break;\r
- \r
- case "h ":\r
- $commands++;\r
- break;\r
- \r
- default:\r
- $errors[]="unknown command: '$arg'";\r
- break;\r
- }\r
- \r
- }\r
- \r
- // are there enough informations to start work?\r
- $errors = $this->checkStatus($errors);\r
- \r
- // check for errors and die() if neccessary\r
- if (count($errors)>0) {\r
- $error = "\n\nCould not understand your request.\n\n";\r
- reset($errors);\r
- while (list($k, $data)=each($errors)) \r
- $error.=$data["msg"]."\n";\r
- \r
- $error.= $this->getArgvHelpMessage();\r
- print $error;\r
- die();\r
- }\r
- \r
- // no errors, but no recognized commands? die() if neccessary\r
- if (0==$commands) {\r
- $error = "\n\nCould not understand your request.\n\n";\r
- $error.= $this->getArgvHelpMessage();\r
- print $error;\r
- die();\r
- }\r
- \r
- // YEAH everything is fine, we can start working!\r
- $this->parse(); \r
- } // end func handleArgv\r
- \r
- /**\r
- * Returns the current help message of phpdoc\r
- * \r
- * The message is not HTML formated, it could be shown \r
- * on the command line. \r
- *\r
- * @access private\r
- * @return string $help_msg Some instructions on available command line options\r
- * @see handleArgv(), $COMMANDS\r
- */ \r
- function getArgvHelpMessage() {\r
- \r
- $help_msg = "";\r
- \r
- // generate the message from the COMMAND array\r
- reset($this->COMMANDS);\r
- while (list($param, $explanation)=each($this->COMMANDS)) \r
- $help_msg.= sprintf("%-28s%s\n", $param, $explanation);\r
- \r
- $help_msg.="\nFurter information can be found in the documentation.\n";\r
- return $help_msg; \r
- } // end func getArgvHelpMessage\r
- \r
-} // end class PhpdocArgvHandler\r
-?>
\ No newline at end of file