1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of CaptainHook. |
4
|
|
|
* |
5
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace sebastianfeldmann\CaptainHook\Console\Command; |
11
|
|
|
|
12
|
|
|
use sebastianfeldmann\CaptainHook\Git\CommitMessage; |
13
|
|
|
use sebastianfeldmann\CaptainHook\Git\Repository; |
14
|
|
|
use sebastianfeldmann\CaptainHook\Runner; |
15
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
17
|
|
|
use Symfony\Component\Console\Input\InputOption; |
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class Run |
22
|
|
|
* |
23
|
|
|
* @package CaptainHook |
24
|
|
|
* @author Sebastian Feldmann <[email protected]> |
25
|
|
|
* @link https://github.com/sebastianfeldmann/captainhook |
26
|
|
|
* @since Class available since Release 0.9.0 |
27
|
|
|
*/ |
28
|
|
|
class Run extends Base |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* Configure the command. |
32
|
|
|
*/ |
33
|
2 |
View Code Duplication |
protected function configure() |
|
|
|
|
34
|
|
|
{ |
35
|
2 |
|
$this->setName('run') |
36
|
2 |
|
->setDescription('Run git hook.') |
37
|
2 |
|
->setHelp("This command executes a configured git hook.") |
38
|
2 |
|
->addArgument('hook', InputArgument::REQUIRED, 'Hook you want to execute.') |
39
|
2 |
|
->addOption('message', 'm', InputOption::VALUE_OPTIONAL, 'File containing the commit message.') |
40
|
2 |
|
->addOption( |
41
|
2 |
|
'configuration', |
42
|
2 |
|
'c', |
43
|
2 |
|
InputOption::VALUE_OPTIONAL, |
44
|
2 |
|
'Path to your json configuration', |
45
|
2 |
|
getcwd() . DIRECTORY_SEPARATOR . 'captainhook.json' |
46
|
|
|
); |
47
|
2 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Execute the command. |
51
|
|
|
* |
52
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
53
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
54
|
|
|
* @return void |
55
|
|
|
*/ |
56
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
57
|
|
|
{ |
58
|
2 |
|
$io = $this->getIO($input, $output); |
59
|
2 |
|
$config = $this->getConfig($input->getOption('configuration'), true); |
60
|
2 |
|
$repo = new Repository(); |
61
|
2 |
|
$msgFile = $input->getOption('message'); |
62
|
2 |
|
if (!empty($msgFile)) { |
63
|
1 |
|
$repo->setCommitMsg(CommitMessage::createFromFile($msgFile)); |
64
|
|
|
} |
65
|
|
|
|
66
|
2 |
|
$hook = new Runner\Hook($io, $config, $repo); |
67
|
2 |
|
$hook->setHook($input->getArgument('hook')); |
68
|
2 |
|
$hook->run(); |
69
|
2 |
|
} |
70
|
|
|
} |
71
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.