stub2ref do not generate <ns>.md
[mdref/mdref] / bin / stub2ref
1 #!/usr/bin/env php
2 <?php
3
4 namespace mdref;
5
6 require_once $_composer_autoload_path ?? __DIR__."/../vendor/autoload.php";
7
8 if ($argc < 3) {
9 fprintf(STDERR, "Usage: %s <ns> <stub.php> [<destination>]\n", $argv[0]);
10 exit(1);
11 }
12
13 $namespace = $argv[1];
14 require_once $argv[2];
15 $destination = ($argc > 3) ? $argv[3] : ".";
16
17 if (!is_dir($destination)) {
18 fprintf(STDERR, "Missing $destination/; Making dir.");
19 mkdir($destination) || exit -1;
20 }
21 if (!file_exists("$destination/$namespace.mdref")) {
22 fprintf(STDERR, "Missing $destination/$namespace.mdref; generated default.\n");
23 file_put_contents("$destination/$namespace.mdref", "./%s") || exit -2;
24 }
25
26 $inspector = new Inspector;
27 $inspector->inspectNamespace($namespace);
28
29 $generator = new Generator($destination);
30 $generator->generateFunctions($inspector->getFunctions());
31 $generator->generateClasses($inspector->getClasses());