1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of CaptainHook |
5
|
|
|
* |
6
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace CaptainHook\App\Console\Command; |
13
|
|
|
|
14
|
|
|
use CaptainHook\App\Console\IOUtil; |
15
|
|
|
use CaptainHook\App\Runner\Config\Editor; |
16
|
|
|
use Exception; |
17
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class Add |
23
|
|
|
* |
24
|
|
|
* @package CaptainHook |
25
|
|
|
* @author Sebastian Feldmann <[email protected]> |
26
|
|
|
* @link https://github.com/captainhook-git/captainhook |
27
|
|
|
* @since Class available since Release 4.2.0 |
28
|
|
|
*/ |
29
|
|
|
class Add extends ConfigAware |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Configure the command |
33
|
|
|
* |
34
|
|
|
* @return void |
35
|
|
|
*/ |
36
|
4 |
|
protected function configure(): void |
37
|
|
|
{ |
38
|
4 |
|
parent::configure(); |
39
|
4 |
|
$this->setName('config:add') |
40
|
4 |
|
->setAliases(['add']) |
41
|
4 |
|
->setDescription('Add an action to your hook configuration') |
42
|
4 |
|
->setHelp('Add an action to your hook configuration') |
43
|
4 |
|
->addArgument('hook', InputArgument::REQUIRED, 'Hook you want to add the action to'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Execute the command |
48
|
|
|
* |
49
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
50
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
51
|
|
|
* @return int |
52
|
|
|
* @throws \CaptainHook\App\Exception\InvalidHookName |
53
|
|
|
* @throws \Exception |
54
|
|
|
*/ |
55
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output): int |
56
|
|
|
{ |
57
|
|
|
try { |
58
|
2 |
|
$io = $this->getIO($input, $output); |
59
|
2 |
|
$config = $this->createConfig($input, true); |
60
|
|
|
|
61
|
1 |
|
$this->determineVerbosity($output, $config); |
62
|
|
|
|
63
|
1 |
|
$editor = new Editor($io, $config); |
64
|
1 |
|
$editor->setHook(IOUtil::argToString($input->getArgument('hook'))) |
65
|
1 |
|
->setChange('AddAction') |
66
|
1 |
|
->run(); |
67
|
|
|
|
68
|
1 |
|
return 0; |
69
|
1 |
|
} catch (Exception $e) { |
70
|
1 |
|
return $this->crash($output, $e); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|