-
Notifications
You must be signed in to change notification settings - Fork 3
/
vismap
executable file
·67 lines (56 loc) · 1.62 KB
/
vismap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env php
<?php
/**
* @file
* Controller for the visual sitemap.
*/
use AKlump\LoftLib\Bash\Bash;
use AKlump\LoftLib\Bash\Color;
use AKlump\LoftLib\Bash\Output;
use AKlump\LoftLib\Storage\FilePath;
use AKlump\VisualSitemap\VisualSitemap;
define('ROOT', dirname(__FILE__));
require_once ROOT . '/includes/autoload.inc';
try {
$cli = new Bash($argv);
$format = $cli->getParam('format', 'html');
// Support for --state=* to produce all files.
if ($cli->getParam('state') === '*') {
$definition = FilePath::create($cli->getArg(1))->load()->getJson(TRUE);
$all_states = VisualSitemap::getDefinedStates($definition);
$all_states[] = NULL;
$key = array_search('--state=*', $argv);
$files_saved = [];
foreach ($all_states as $state) {
$edited_argv = $argv;
$edited_argv[$key] = '--state=' . $state;
if (!$state) {
unset($edited_argv[$key]);
}
$cli = new Bash($edited_argv);
require ROOT . '/includes/bootstrap.inc';
$files_saved = array_merge($files_saved, $vismap->generate()->save());
}
}
else {
require ROOT . '/includes/bootstrap.inc';
switch ($format) {
case 'json':
$files_saved = $vismap->generateJson()->save();
break;
case 'list':
$files_saved = $vismap->generateTextList()->save();
break;
case 'html':
$files_saved = $vismap->generate()->save();
break;
}
}
}
catch (\Exception $exception) {
echo Color::wrap('red', $exception->getMessage() . PHP_EOL);
exit(1);
}
echo Color::wrap('green', 'Files created:') . PHP_EOL;
echo Output::tree($files_saved);
exit(0);