1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2017 Julius Härtl <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @author Julius Härtl <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @license GNU AGPL version 3 or any later version |
8
|
|
|
* |
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
12
|
|
|
* License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace JuliusHaertl\PHPDocToRst; |
25
|
|
|
|
26
|
|
|
use JuliusHaertl\PHPDocToRst\Extension\AddFullElementNameExtension; |
27
|
|
|
use JuliusHaertl\PHPDocToRst\Extension\GithubLocationExtension; |
28
|
|
|
use JuliusHaertl\PHPDocToRst\Extension\NoPrivateExtension; |
29
|
|
|
use JuliusHaertl\PHPDocToRst\Extension\PublicOnlyExtension; |
30
|
|
|
use JuliusHaertl\PHPDocToRst\Extension\TocExtension; |
31
|
|
|
use Symfony\Component\Console\Command\Command; |
32
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
33
|
|
|
use Symfony\Component\Console\Input\InputOption; |
34
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
35
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Class GenerateDocumentationCommand |
39
|
|
|
* @package JuliusHaertl\PHPDocToRst |
40
|
|
|
* @internal Only for use of the phpdoc-to-rst cli tool |
41
|
|
|
*/ |
42
|
|
|
class GenerateDocumentationCommand extends Command { |
43
|
|
|
|
44
|
|
|
protected function configure() { |
45
|
|
|
$this |
46
|
|
|
->setName('generate') |
47
|
|
|
->setDescription('Generate documentation') |
48
|
|
|
->setHelp('This command allows you to generate sphinx/rst based documentation from PHPDoc annotations.') |
49
|
|
|
->addArgument('target', InputArgument::REQUIRED, 'Destination for the generated rst files') |
50
|
|
|
->addArgument( |
51
|
|
|
'src', |
52
|
|
|
InputArgument::IS_ARRAY, |
53
|
|
|
'Source directories to parse') |
54
|
|
|
->addOption('public-only', 'p', InputOption::VALUE_NONE) |
55
|
|
|
->addOption('show-private', null, InputOption::VALUE_NONE) |
56
|
|
|
->addOption('element-toc', 't', InputOption::VALUE_NONE) |
57
|
|
|
->addOption('repo-github', null, InputOption::VALUE_REQUIRED, 'Github URL of the projects git repository (requires --repo-base as well)', false) |
58
|
|
|
->addOption('repo-base', null, InputOption::VALUE_REQUIRED, 'Base path of the project git repository', false); |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
63
|
|
|
$src = $input->getArgument('src'); |
64
|
|
|
$dst = $input->getArgument('target'); |
65
|
|
|
|
66
|
|
|
$apiDocBuilder = new ApiDocBuilder($src, $dst); |
67
|
|
|
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { |
68
|
|
|
$apiDocBuilder->setVerboseOutput(true); |
69
|
|
|
} |
70
|
|
|
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) { |
71
|
|
|
$apiDocBuilder->setVerboseOutput(true); |
72
|
|
|
$apiDocBuilder->setDebugOutput(true); |
73
|
|
|
} |
74
|
|
|
if($input->getOption('public-only')) { |
75
|
|
|
$apiDocBuilder->addExtension(PublicOnlyExtension::class); |
76
|
|
|
} |
77
|
|
|
if(!$input->getOption('show-private')) { |
78
|
|
|
$apiDocBuilder->addExtension(NoPrivateExtension::class); |
79
|
|
|
} |
80
|
|
|
if($input->getOption('element-toc')) { |
81
|
|
|
$apiDocBuilder->addExtension(TocExtension::class); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
if($input->getOption('repo-github') && $input->getOption('repo-base')) { |
85
|
|
|
$apiDocBuilder->addExtension(GithubLocationExtension::class, [ |
86
|
|
|
$input->getOption('repo-base'), |
87
|
|
|
$input->getOption('repo-github') |
88
|
|
|
]); |
89
|
|
|
} |
90
|
|
|
$apiDocBuilder->build(); |
91
|
|
|
} |
92
|
|
|
} |