|
31 | 31 | ->opt('header_image:i', 'Specifies an image to display in the header.', false, 'string')
|
32 | 32 | ->opt('css:c', 'Specifies a CSS file to include (value is put in a link element without checking).', false, 'string')
|
33 | 33 | ->opt('javascript:j', 'Specifies a JS file to include (value is put in a script element without checking).', false, 'string')
|
34 |
| - ->opt('version:v', 'Print the version for PHPDraft.', false); |
| 34 | + ->opt('version:v', 'Print the version for PHPDraft.', false) |
| 35 | + ->opt('debug-json-file', 'Input a rendered JSON file for debugging.', false, 'string') |
| 36 | + ->opt('debug-json', 'Input a rendered JSON text for debugging.', false, 'string'); |
35 | 37 |
|
36 | 38 | // Parse and return cli args.
|
37 | 39 | $args = $cli->parse($argv, FALSE);
|
38 | 40 | if (isset($args['version'])) {
|
39 | 41 | Version::version();
|
40 | 42 | throw new ExecutionException('', 0);
|
41 | 43 | }
|
42 |
| - if (!isset($args['file'])) { |
| 44 | + if (!(isset($args['file']) || isset($args['debug-json-file']) || isset($args['debug-json']))) { |
43 | 45 | throw new ExecutionException('Missing required option: file', 1);
|
44 | 46 | }
|
45 | 47 |
|
|
48 | 50 | define('DRAFTER_ONLINE_MODE', 1);
|
49 | 51 | }
|
50 | 52 |
|
51 |
| - $apib = new ApibFileParser($args->getOpt('file')); |
52 |
| - $apib = $apib->parse(); |
53 |
| - $offline = FALSE; |
54 |
| - $online = FALSE; |
| 53 | + if (!isset($args['debug-json-file']) && !isset($args['debug-json'])) { |
| 54 | + $apib = new ApibFileParser($args->getOpt('file')); |
| 55 | + $apib = $apib->parse(); |
| 56 | + $offline = FALSE; |
| 57 | + $online = FALSE; |
55 | 58 |
|
56 |
| - try |
57 |
| - { |
58 |
| - $parser = ParserFactory::getDrafter(); |
59 |
| - $parser = $parser->init($apib); |
60 |
| - $data = $parser->parseToJson(); |
61 |
| - } |
62 |
| - catch (ResourceException $exception) |
63 |
| - { |
64 |
| - throw new ExecutionException('No drafter available', 255); |
| 59 | + try { |
| 60 | + $parser = ParserFactory::getDrafter(); |
| 61 | + $parser = $parser->init($apib); |
| 62 | + $data = $parser->parseToJson(); |
| 63 | + } catch (ResourceException $exception) { |
| 64 | + throw new ExecutionException('No drafter available', 255); |
| 65 | + } |
| 66 | + } else { |
| 67 | + $json_string = $args['debug-json'] ?? file_get_contents($args['debug-json-file']); |
| 68 | + $data = json_decode($json_string); |
65 | 69 | }
|
66 | 70 |
|
67 | 71 | $html = ParserFactory::getJson()->init($data);
|
|
0 commit comments