Skip to content

Commit 4c605e5

Browse files
committed
cli improve
1 parent d7729b1 commit 4c605e5

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

index.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
use Symfony\Component\Console\Output\OutputInterface;
77

88
/** @var \Composer\Autoload\ClassLoader $autoLoader */
9-
$autoLoader = require_once 'vendor/autoload.php';
9+
$autoLoader = require_once __DIR__.'/vendor/autoload.php';
1010
$autoLoader->addPsr4('e96\\', __DIR__);
1111

12-
$app = new Silly\Application();
12+
$app = new Silly\Application('swagger2slate', 'dev-master');
1313

14-
$app->command('convert inputFile outputFile', function($inputFile, $outputFile, OutputInterface $output) {
14+
$app->command('convert inputFile [-o|--outputFile=]', function($inputFile, $outputFile, OutputInterface $output) use ($app) {
1515
$config = json_decode(file_get_contents($inputFile), true);
1616
if ($config['swagger'] != '2.0') {
1717
$output->writeln('swagger version must be 2.0');
18-
return;
18+
return 1;
1919
}
2020
Swagger::$root = $config;
2121
$swagger = new Swagger($config);
@@ -96,10 +96,16 @@
9696
'api' => $swagger,
9797
));
9898

99-
file_put_contents($outputFile, $slate);
99+
if (!empty($outputFile)) {
100+
file_put_contents($outputFile, $slate);
101+
} else {
102+
$output->writeln($slate);
103+
}
104+
105+
return 0;
100106
})->descriptions('Converts swagger.json to slate markdown file', [
101107
'inputFile' => 'swagger.json file path',
102-
'outputFile' => 'source/index.md file path',
108+
'--outputFile' => 'source/index.md file path',
103109
]);
104110

105111
$app->run();

0 commit comments

Comments
 (0)