#!/usr/local/bin/php -q
<?php

/** PHP auto documentor, like javadoc
 *  If you get an error uses this as a shell script then its been dosified
 *  @author Joshua Eichorn
 *  @version .0.1.0
 */

include("Parse.inc");
include("Template.inc");

// Parse ARGV
$errormsg = "
-f filename     name of file to parse
-d directory    name of a directory to parse
-t target       path where to save the generated files, default is the current path (not supported must input path)
-h              show this help message
";
foreach ( $argv as $cmd )
{
        $setting[$valnext] = $cmd;
        switch($cmd) {
                case "-d":
                        $valnext = "directory";
                break;
                case "-f":
                        $valnext = "file";
                break;
                case "-t":
                        $valnext = "target";
                break;
                case "-h":
                        echo $errormsg;
                        die();
                break;
                default:
                        $valnext = "junk";
                break;
        }
}


if (count($setting) < 2) {
        echo "No arguments specified\n";
        echo $errormsg;
        die();
}

$phpdoc = new Parse;
$phpdoc->setTargetDir($setting[target]);

// is it a file or a dir
if (strlen($setting[file]) > 0)
{
        $phpdoc->create($setting[file]);
        $phpdoc->render();
        $phpdoc->createIndex();
} else {
        $files = $phpdoc->dirList($setting[directory]);
        foreach($files as $file)
        {
                $phpdoc->create($file);
        }
        $phpdoc->render();
        $phpdoc->createIndex();
}
?>
