Skip to content

Commit 9b282a9

Browse files
committed
Base: add types
1 parent 5c09be5 commit 9b282a9

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

phpdraft

+20-16
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,25 @@ try
2525
// Define the cli options.
2626
$cli = new Cli();
2727
$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)
3629
->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);
3940

4041
// Parse and return cli args.
4142
$args = $cli->parse($argv, FALSE);
43+
if (isset($args['help']) || empty($args->getOpts())) {
44+
$cli->writeHelp();
45+
throw new ExecutionException('', 0);
46+
}
4247
if (isset($args['version'])) {
4348
Version::version();
4449
throw new ExecutionException('', 0);
@@ -53,6 +58,10 @@ try
5358
$file = tempnam(sys_get_temp_dir(), 'phpdraft');
5459
file_put_contents($file, $stdin);
5560
}
61+
if ($file === NULL || $file === '')
62+
{
63+
throw new ExecutionException('ERROR: File does not exist', 200);
64+
}
5665

5766
if (!($file !== NULL || isset($args['debug-json-file']) || isset($args['debug-json']))) {
5867
throw new ExecutionException('Missing required option: file', 1);
@@ -97,12 +106,7 @@ try
97106

98107
echo $html;
99108
}
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)
106110
{
107111
file_put_contents('php://stderr', $exception->getMessage() . PHP_EOL);
108112
exit($exception->getCode());

0 commit comments

Comments
 (0)