Skip to content

Commit 2c21889

Browse files
committed
added output option
1 parent 4b07bd8 commit 2c21889

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/GenerateSwaggerDoc.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ class GenerateSwaggerDoc extends Command
1313
*/
1414
protected $signature = 'laravel-swagger:generate
1515
{--format=json : The format of the output, current options are json and yaml}
16-
{--filter= : Filter to a specific route prefix, such as /api or /v2/api}';
16+
{--f|filter= : Filter to a specific route prefix, such as /api or /v2/api}
17+
{--o|output= : Output file to write the contents to, defaults to stdout}';
1718

1819
/**
1920
* The console command description.
@@ -30,13 +31,19 @@ class GenerateSwaggerDoc extends Command
3031
public function handle()
3132
{
3233
$config = config('laravel-swagger');
34+
$filter = $this->option('filter') ?: null;
35+
$file = $this->option('output') ?: null;
3336

34-
$docs = (new Generator($config, $this->option('filter') ?: null))->generate();
37+
$docs = (new Generator($config, $filter))->generate();
3538

3639
$formattedDocs = (new FormatterManager($docs))
3740
->setFormat($this->option('format'))
3841
->format();
3942

40-
$this->line($formattedDocs);
43+
if ($file) {
44+
file_put_contents($file, $formattedDocs);
45+
} else {
46+
$this->line($formattedDocs);
47+
}
4148
}
42-
}
49+
}

0 commit comments

Comments
 (0)