-
Notifications
You must be signed in to change notification settings - Fork 8
/
ocs
executable file
·42 lines (37 loc) · 1.38 KB
/
ocs
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
#!/usr/bin/env php
<?php
use Garden\Cli\Cli;
require "vendor/autoload.php";
$cli = new Cli();
$cli->description('OpenCore config.plist sanity checker')
->opt('ruleset:r', 'Rule set to check against', true, 'string')
->opt('markdown:m', 'Leave output in markdown format', false, 'boolean')
->arg('plist', 'config.plist to sanity check', true);
$args = $cli->parse($argv);
$plist = $args->getArg('plist');
$rules = $args->getOpt('ruleset');
$md = $args->getOpt('markdown');
$pd = new ParsedownExtra();
$results = function() use($plist,$rules,$md) {
$old = set_error_handler("grabErrors");
ob_start(function($buf) use($md) {
if($md) return $buf;
$pd = new ParsedownExtra();
return $pd->text($buf);
});
$oc = null;
try {
$oc = new OpenCorePlist($plist);
} catch (DOMException $e) {
echo "This config.plist contains XML syntax errors and will not parse";
}
if($oc) $oc->applyRules(new Rules($rules));
ob_end_flush();
set_error_handler($old);
};
$results();
function grabErrors($errno, $errstr, $errfile, $errline) {
if(preg_match("@DOMDocument::load\(\): (.*?) in.*line: (\d+)@", $errstr, $match)) {
echo $match[1]." line ".$match[2]."\n";
}
}