1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
namespace PhpTaskman\Core\Robo\Plugin\Commands; |
6
|
|
|
|
7
|
|
|
use Consolidation\AnnotatedCommand\AnnotatedCommand; |
8
|
|
|
use PhpTaskman\Core\Common\NullOutputAdapter; |
|
|
|
|
9
|
|
|
use PhpTaskman\Core\Robo\Task\PreconditionsCollectionFactoryTask; |
|
|
|
|
10
|
|
|
use PhpTaskman\CoreTasks\Plugin\Task\CollectionFactoryTask; |
11
|
|
|
use Robo\Collection\CollectionBuilder; |
12
|
|
|
use Robo\Contract\VerbosityThresholdInterface; |
13
|
|
|
use Robo\Exception\TaskException; |
14
|
|
|
use Symfony\Component\Console\Event\ConsoleCommandEvent; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class DynamicCommands. |
18
|
|
|
*/ |
19
|
|
|
final class YamlCommands extends AbstractCommands |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Bind input values of custom command options to config entries. |
23
|
|
|
* |
24
|
|
|
* @param \Symfony\Component\Console\Event\ConsoleCommandEvent $event |
25
|
|
|
* |
26
|
|
|
* @hook pre-command-event * |
27
|
|
|
*/ |
28
|
|
|
public function bindInputOptionsToConfig(ConsoleCommandEvent $event): void |
29
|
|
|
{ |
30
|
|
|
$command = $event->getCommand(); |
31
|
|
|
|
32
|
|
|
if (null === $command) { |
33
|
|
|
return; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
if (AnnotatedCommand::class !== \get_class($command)) { |
37
|
|
|
return; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
if (!($command instanceof AnnotatedCommand)) { |
41
|
|
|
return; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** @var \Consolidation\AnnotatedCommand\AnnotatedCommand $command */ |
45
|
|
|
/** @var \Consolidation\AnnotatedCommand\AnnotationData $annotatedData */ |
46
|
|
|
$annotatedData = $command->getAnnotationData(); |
47
|
|
|
|
48
|
|
|
if (!$annotatedData->get('dynamic-command')) { |
49
|
|
|
return; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
// Dynamic commands may define their own options bound to specific configuration. Dynamically set the |
53
|
|
|
// configuration from command options. |
54
|
|
|
$config = $this->getConfig(); |
55
|
|
|
$commands = $config->get('commands'); |
56
|
|
|
|
57
|
|
|
if (empty($commands[$command->getName()]['options'])) { |
58
|
|
|
return; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
foreach ($commands[$command->getName()]['options'] as $optionName => $option) { |
62
|
|
|
if (empty($option['config']) && $event->getInput()->hasOption($optionName)) { |
63
|
|
|
continue; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$inputValue = $event->getInput()->getOption($optionName); |
67
|
|
|
|
68
|
|
|
if (null === $inputValue) { |
69
|
|
|
continue; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$config->set( |
73
|
|
|
$option['config'], |
74
|
|
|
$event->getInput()->getOption($optionName) |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* {@inheritdoc} |
81
|
|
|
*/ |
82
|
|
|
public function getConfigurationFile(): string |
83
|
|
|
{ |
84
|
|
|
return __DIR__ . '/../../../../config/commands/default.yml'; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* {@inheritdoc} |
89
|
|
|
*/ |
90
|
|
|
public function getDefaultConfigurationFile(): string |
91
|
|
|
{ |
92
|
|
|
return __DIR__ . '/../../../../config/default.yml'; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Run a task. |
97
|
|
|
* |
98
|
|
|
* @dynamic-command true |
99
|
|
|
* |
100
|
|
|
* @throws \Robo\Exception\TaskException |
101
|
|
|
* |
102
|
|
|
* @return \Robo\Collection\CollectionBuilder |
103
|
|
|
*/ |
104
|
|
|
public function runTasks(): CollectionBuilder |
105
|
|
|
{ |
106
|
|
|
$command = $this->input()->getArgument('command'); |
107
|
|
|
|
108
|
|
|
if (!\is_string($command)) { |
109
|
|
|
throw new TaskException($this, 'The command must be a string.'); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
$inputOptions = []; |
113
|
|
|
|
114
|
|
|
foreach ($this->input()->getOptions() as $name => $value) { |
115
|
|
|
if ($this->input()->hasParameterOption('--' . $name)) { |
116
|
|
|
$inputOptions[$name] = $value; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
$command = $this->getConfig()->get('commands.' . $command); |
121
|
|
|
|
122
|
|
|
// Handle different types of command definitions. |
123
|
|
|
if (isset($command['tasks'])) { |
124
|
|
|
$arguments = [ |
125
|
|
|
'tasks' => $command['tasks'], |
126
|
|
|
'options' => $inputOptions, |
127
|
|
|
'preconditions' => $command['preconditions'] ?? [], |
128
|
|
|
]; |
129
|
|
|
|
130
|
|
|
if (is_string($arguments['preconditions'])) { |
131
|
|
|
$arguments['preconditions'] = [$arguments['preconditions']]; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** @var CollectionFactoryTask $preconditionsTask */ |
135
|
|
|
$preconditionsTask = $this->task(CollectionFactoryTask::class); |
136
|
|
|
$preconditionsTask->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_DEBUG); |
137
|
|
|
$preconditionsTask->setTaskArguments([ |
138
|
|
|
'tasks' => $arguments['preconditions'], |
139
|
|
|
]); |
140
|
|
|
|
141
|
|
|
if (0 !== $preconditionsTask->run()->getExitCode()) { |
142
|
|
|
$arguments['tasks'] = []; |
143
|
|
|
} |
144
|
|
|
} else { |
145
|
|
|
$arguments = [ |
146
|
|
|
'tasks' => $command, |
147
|
|
|
'options' => [], |
148
|
|
|
]; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** @var CollectionFactoryTask $collectionFactory */ |
152
|
|
|
$collectionFactory = $this->task(CollectionFactoryTask::class); |
153
|
|
|
|
154
|
|
|
return $collectionFactory->setTaskArguments($arguments); |
|
|
|
|
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths