|
25 | 25 | // Define the cli options.
|
26 | 26 | $cli = new Cli();
|
27 | 27 | $cli->description('Parse API Blueprint files.')
|
28 |
| - ->opt('file:f', 'Specifies the file to parse.', false, 'string') |
29 |
| - ->opt('yes:y', 'Always accept using the online mode.', false) |
30 |
| - ->opt('online:o', 'Always use the online mode.', false) |
31 |
| - ->opt('template:t', 'Specifies the template to use. (defaults to \'default\').', false, 'string') |
32 |
| - ->opt('sort:s', 'Sort displayed values [All|None|Structures|Webservices] (defaults to the way the objects are in the file).', false, 'string') |
33 |
| - ->opt('header_image:i', 'Specifies an image to display in the header.', false, 'string') |
34 |
| - ->opt('css:c', 'Specifies a CSS file to include (value is put in a link element without checking).', false, 'string') |
35 |
| - ->opt('javascript:j', 'Specifies a JS file to include (value is put in a script element without checking).', false, 'string') |
| 28 | + ->opt('help:h', 'This help text', false) |
36 | 29 | ->opt('version:v', 'Print the version for PHPDraft.', false)
|
37 |
| - ->opt('debug-json-file', 'Input a rendered JSON file for debugging.', false, 'string') |
38 |
| - ->opt('debug-json', 'Input a rendered JSON text for debugging.', false, 'string'); |
| 30 | + ->opt('file:f', 'Specifies the file to parse.', false) |
| 31 | + ->opt('yes:y', 'Always accept using the online mode.', false, 'bool') |
| 32 | + ->opt('online:o', 'Always use the online mode.', false, 'bool') |
| 33 | + ->opt('template:t', 'Specifies the template to use. (defaults to \'default\').', false) |
| 34 | + ->opt('sort:s', 'Sort displayed values [All|None|Structures|Webservices] (defaults to the way the objects are in the file).', false) |
| 35 | + ->opt('header_image:i', 'Specifies an image to display in the header.', false) |
| 36 | + ->opt('css:c', 'Specifies a CSS file to include (value is put in a link element without checking).', false) |
| 37 | + ->opt('javascript:j', 'Specifies a JS file to include (value is put in a script element without checking).', false) |
| 38 | + ->opt('debug-json-file', 'Input a rendered JSON file for debugging.', false) |
| 39 | + ->opt('debug-json', 'Input a rendered JSON text for debugging.', false); |
39 | 40 |
|
40 | 41 | // Parse and return cli args.
|
41 | 42 | $args = $cli->parse($argv, FALSE);
|
| 43 | + if (isset($args['help']) || empty($args->getOpts())) { |
| 44 | + $cli->writeHelp(); |
| 45 | + throw new ExecutionException('', 0); |
| 46 | + } |
42 | 47 | if (isset($args['version'])) {
|
43 | 48 | Version::version();
|
44 | 49 | throw new ExecutionException('', 0);
|
|
53 | 58 | $file = tempnam(sys_get_temp_dir(), 'phpdraft');
|
54 | 59 | file_put_contents($file, $stdin);
|
55 | 60 | }
|
| 61 | + if ($file === NULL || $file === '') |
| 62 | + { |
| 63 | + throw new ExecutionException('ERROR: File does not exist', 200); |
| 64 | + } |
56 | 65 |
|
57 | 66 | if (!($file !== NULL || isset($args['debug-json-file']) || isset($args['debug-json']))) {
|
58 | 67 | throw new ExecutionException('Missing required option: file', 1);
|
|
97 | 106 |
|
98 | 107 | echo $html;
|
99 | 108 | }
|
100 |
| -catch (ExecutionException $exception) |
101 |
| -{ |
102 |
| - file_put_contents('php://stderr', $exception->getMessage() . PHP_EOL); |
103 |
| - exit($exception->getCode()); |
104 |
| -} |
105 |
| -catch (Exception $exception) |
| 109 | +catch (ExecutionException|Exception $exception) |
106 | 110 | {
|
107 | 111 | file_put_contents('php://stderr', $exception->getMessage() . PHP_EOL);
|
108 | 112 | exit($exception->getCode());
|
|
0 commit comments