-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAddDocBlocksCommand.php
65 lines (55 loc) · 2.1 KB
/
AddDocBlocksCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
declare(strict_types=1);
namespace BumbleDocGen\AI\Console;
use BumbleDocGen\AI\Traits\SharedCommandLogicTrait;
use BumbleDocGen\Console\Command\BaseCommand;
use BumbleDocGen\Core\Configuration\Exception\InvalidConfigurationParameterException;
use BumbleDocGen\LanguageHandler\Php\Parser\Entity\Exception\ReflectionException;
use DI\DependencyException;
use DI\NotFoundException;
use GuzzleHttp\Exception\GuzzleException;
use JsonException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
final class AddDocBlocksCommand extends BaseCommand
{
use SharedCommandLogicTrait;
public const NAME = 'ai:add-doc-blocks';
protected function getCustomConfigOptionsMap(): array
{
return [
'project_root' => 'Path to the directory of the documented project',
'templates_dir' => 'Path to directory with documentation templates',
'cache_dir' => 'Configuration parameter: Path to the directory where the documentation generator cache will be saved',
'ai_provider' => 'The AI service to use, options: openai',
'ai_api_key' => 'The API key to use when interacting with the AI',
'ai_model' => 'The AI model to use',
];
}
protected function configure(): void
{
$this->setName(self::NAME)
->setDescription('Leverage AI to insert missing doc blocks in code.');
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
* @throws DependencyException
* @throws InvalidConfigurationParameterException
* @throws NotFoundException
* @throws ReflectionException
* @throws GuzzleException
* @throws JsonException
*/
protected function execute(
InputInterface $input,
OutputInterface $output
): int {
// Initialise AI provider from params/config
$aiProvider = $this->initAiProvider($input, $output);
// Generate doc blocks
$this->createDocGenInstance($input, $output)->addDocBlocks($aiProvider);
return self::SUCCESS;
}
}