6
6
use Symfony \Component \Console \Output \OutputInterface ;
7
7
8
8
/** @var \Composer\Autoload\ClassLoader $autoLoader */
9
- $ autoLoader = require_once ' vendor/autoload.php ' ;
9
+ $ autoLoader = require_once __DIR__ . ' / vendor/autoload.php ' ;
10
10
$ autoLoader ->addPsr4 ('e96 \\' , __DIR__ );
11
11
12
- $ app = new Silly \Application ();
12
+ $ app = new Silly \Application (' swagger2slate ' , ' dev-master ' );
13
13
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 ) {
15
15
$ config = json_decode (file_get_contents ($ inputFile ), true );
16
16
if ($ config ['swagger ' ] != '2.0 ' ) {
17
17
$ output ->writeln ('swagger version must be 2.0 ' );
18
- return ;
18
+ return 1 ;
19
19
}
20
20
Swagger::$ root = $ config ;
21
21
$ swagger = new Swagger ($ config );
96
96
'api ' => $ swagger ,
97
97
));
98
98
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 ;
100
106
})->descriptions ('Converts swagger.json to slate markdown file ' , [
101
107
'inputFile ' => 'swagger.json file path ' ,
102
- 'outputFile ' => 'source/index.md file path ' ,
108
+ '-- outputFile ' => 'source/index.md file path ' ,
103
109
]);
104
110
105
111
$ app ->run ();
0 commit comments