X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=bin%2Fstub2ref;fp=bin%2Fstub2ref;h=37e55f23b241cb17b8086c1d42511ed4d010c5c2;hb=99cb230e2fb744ba7d689a791e0b2f64b0c122ba;hp=f0d11b197151010aabe88d58a8c81793aecc5890;hpb=5049ac5407240b679b54f26dcdcb6dca4e478217;p=mdref%2Fmdref diff --git a/bin/stub2ref b/bin/stub2ref index f0d11b1..37e55f2 100755 --- a/bin/stub2ref +++ b/bin/stub2ref @@ -6,25 +6,30 @@ namespace mdref; require_once $_composer_autoload_path ?? __DIR__."/../vendor/autoload.php"; if ($argc < 3) { - fprintf(STDERR, "Usage: cd ref- && %s \n", $argv[0]); + fprintf(STDERR, "Usage: %s []\n", $argv[0]); exit(1); } $namespace = $argv[1]; require_once $argv[2]; +$destination = ($argc > 3) ? $argv[3] : "."; -if (!file_exists("$namespace.mdref")) { - fprintf(STDERR, "Missing $namespace.mdref; generated default.\n"); - file_put_contents("$namespace.mdref", "./%s"); +if (!is_dir($destination)) { + fprintf(STDERR, "Missing $destination/; Making dir."); + mkdir($destination) || exit -1; } -if (!file_exists("$namespace.md")) { - fprintf(STDERR, "Missing $namespace.md; hard linking README.md\n"); - link(dirname($argv[2]) . "/README.md", "$namespace.md"); +if (!file_exists("$destination/$namespace.mdref")) { + fprintf(STDERR, "Missing $destination/$namespace.mdref; generated default.\n"); + file_put_contents("$destination/$namespace.mdref", "./%s") || exit -2; +} +if (!file_exists("$destination/$namespace.md")) { + fprintf(STDERR, "Missing $destination/$namespace.md; hard linking README.md\n"); + link(dirname($argv[2]) . "/README.md", "$destination/$namespace.md") || exit -3; } $inspector = new Inspector; $inspector->inspectNamespace($namespace); -$generator = new Generator; +$generator = new Generator($destination); $generator->generateFunctions($inspector->getFunctions()); $generator->generateClasses($inspector->getClasses());