From 4c605e5dcfcc3a630ce69bebf1357e9a1546552d Mon Sep 17 00:00:00 2001 From: m8rge Date: Mon, 20 Apr 2015 09:01:21 +0500 Subject: [PATCH] cli improve --- index.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/index.php b/index.php index d702205..604e17f 100644 --- a/index.php +++ b/index.php @@ -6,16 +6,16 @@ use Symfony\Component\Console\Output\OutputInterface; /** @var \Composer\Autoload\ClassLoader $autoLoader */ -$autoLoader = require_once 'vendor/autoload.php'; +$autoLoader = require_once __DIR__.'/vendor/autoload.php'; $autoLoader->addPsr4('e96\\', __DIR__); -$app = new Silly\Application(); +$app = new Silly\Application('swagger2slate', 'dev-master'); -$app->command('convert inputFile outputFile', function($inputFile, $outputFile, OutputInterface $output) { +$app->command('convert inputFile [-o|--outputFile=]', function($inputFile, $outputFile, OutputInterface $output) use ($app) { $config = json_decode(file_get_contents($inputFile), true); if ($config['swagger'] != '2.0') { $output->writeln('swagger version must be 2.0'); - return; + return 1; } Swagger::$root = $config; $swagger = new Swagger($config); @@ -96,10 +96,16 @@ 'api' => $swagger, )); - file_put_contents($outputFile, $slate); + if (!empty($outputFile)) { + file_put_contents($outputFile, $slate); + } else { + $output->writeln($slate); + } + + return 0; })->descriptions('Converts swagger.json to slate markdown file', [ 'inputFile' => 'swagger.json file path', - 'outputFile' => 'source/index.md file path', + '--outputFile' => 'source/index.md file path', ]); $app->run(); \ No newline at end of file