1 | <?php |
||
2 | /** |
||
3 | * Copyright (c) 2020. |
||
4 | * @author Paweł Antosiak <[email protected]> |
||
5 | */ |
||
6 | |||
7 | declare(strict_types=1); |
||
8 | |||
9 | namespace Gorynych\Command; |
||
10 | |||
11 | use Gorynych\Generator\FileWriter; |
||
12 | use Gorynych\Util\EnvAccess; |
||
13 | use Gorynych\Util\OAReader; |
||
14 | use Symfony\Component\Console\Command\Command; |
||
15 | use Symfony\Component\Console\Input\InputArgument; |
||
16 | use Symfony\Component\Console\Input\InputInterface; |
||
17 | use Symfony\Component\Console\Output\OutputInterface; |
||
18 | use Symfony\Component\Console\Style\SymfonyStyle; |
||
19 | |||
20 | final class UpdateApiDocsCommand extends Command |
||
21 | { |
||
22 | protected static $defaultName = 'gorynych:update-api-docs'; |
||
23 | |||
24 | private FileWriter $fileWriter; |
||
25 | private OAReader $oaReader; |
||
26 | |||
27 | public function __construct(FileWriter $fileWriter, OAReader $oaReader) |
||
28 | { |
||
29 | parent::__construct(); |
||
30 | |||
31 | $this->fileWriter = $fileWriter; |
||
32 | $this->oaReader = $oaReader; |
||
33 | } |
||
34 | |||
35 | protected function configure(): void |
||
36 | { |
||
37 | $this |
||
38 | ->setDescription('Updates Open API documentation.') |
||
39 | ->addArgument('outputPath', InputArgument::OPTIONAL, 'API documentation file output path'); |
||
40 | } |
||
41 | |||
42 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
43 | { |
||
44 | $io = new SymfonyStyle($input, $output); |
||
45 | $path = EnvAccess::get('PROJECT_DIR') . ($input->getArgument('outputPath') ?? '/openapi/openapi.yaml'); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
46 | |||
47 | $this->fileWriter->forceOverwrite()->write($path, $this->oaReader->read()->toYaml()); |
||
48 | |||
49 | $io->success("Docs updated at path {$path}"); |
||
50 | |||
51 | return 0; |
||
52 | } |
||
53 | } |
||
54 |