1
|
|
|
<?php |
2
|
|
|
namespace Yoanm\ComposerConfigManager\Infrastructure\Command; |
3
|
|
|
|
4
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
5
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
6
|
|
|
use Symfony\Component\Console\Input\InputOption; |
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
8
|
|
|
use Yoanm\ComposerConfigManager\Application\CreateConfiguration; |
9
|
|
|
use Yoanm\ComposerConfigManager\Application\CreateConfigurationRequest; |
10
|
|
|
use Yoanm\ComposerConfigManager\Application\Loader\ConfigurationLoaderInterface; |
11
|
|
|
use Yoanm\ComposerConfigManager\Domain\Model\Configuration; |
12
|
|
|
use Yoanm\ComposerConfigManager\Infrastructure\Command\Transformer\InputTransformer; |
13
|
|
|
|
14
|
|
|
class CreateConfigurationCommand extends AbstractTemplatableCommand |
15
|
|
|
{ |
16
|
|
|
const NAME = 'create'; |
17
|
|
|
const ARGUMENT_CONFIGURATION_DEST_FOLDER = 'destination'; |
18
|
|
|
|
19
|
|
|
/** @var InputTransformer */ |
20
|
|
|
private $inputTransformer; |
21
|
|
|
/** @var CreateConfiguration */ |
22
|
|
|
private $createConfiguration; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param InputTransformer $inputTransformer |
26
|
|
|
* @param CreateConfiguration $createConfiguration |
27
|
|
|
* @param ConfigurationLoaderInterface $configurationLoader |
28
|
|
|
*/ |
29
|
|
|
public function __construct( |
30
|
|
|
InputTransformer $inputTransformer, |
31
|
|
|
CreateConfiguration $createConfiguration, |
32
|
|
|
ConfigurationLoaderInterface $configurationLoader |
33
|
|
|
) { |
34
|
|
|
parent::__construct($configurationLoader); |
35
|
|
|
|
36
|
|
|
$this->inputTransformer = $inputTransformer; |
37
|
|
|
$this->createConfiguration = $createConfiguration; |
38
|
|
|
} |
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
|
|
protected function configure() |
43
|
|
|
{ |
44
|
|
|
$this |
45
|
|
|
->setName(self::NAME) |
46
|
|
|
->setDescription('Will create a composer configuration file') |
47
|
|
|
->addArgument( |
48
|
|
|
InputTransformer::KEY_PACKAGE_NAME, |
49
|
|
|
InputArgument::REQUIRED, |
50
|
|
|
'Name for the composer package' |
51
|
|
|
) |
52
|
|
|
->addArgument( |
53
|
|
|
self::ARGUMENT_CONFIGURATION_DEST_FOLDER, |
54
|
|
|
InputArgument::OPTIONAL, |
55
|
|
|
'Configuration file destination folder', |
56
|
|
|
'.' |
57
|
|
|
) |
58
|
|
|
->addOption( |
59
|
|
|
InputTransformer::KEY_TYPE, |
60
|
|
|
null, |
61
|
|
|
InputOption::VALUE_REQUIRED, |
62
|
|
|
'Package type. Ex : "library" / "project"' |
63
|
|
|
) |
64
|
|
|
->addOption( |
65
|
|
|
InputTransformer::KEY_LICENSE, |
66
|
|
|
null, |
67
|
|
|
InputOption::VALUE_REQUIRED, |
68
|
|
|
'Package license type' |
69
|
|
|
) |
70
|
|
|
->addOption( |
71
|
|
|
InputTransformer::KEY_PACKAGE_VERSION, |
72
|
|
|
null, |
73
|
|
|
InputOption::VALUE_REQUIRED, |
74
|
|
|
'Package version number. Ex : "X.Y.Z"' |
75
|
|
|
) |
76
|
|
|
->addOption( |
77
|
|
|
InputTransformer::KEY_DESCRIPTION, |
78
|
|
|
null, |
79
|
|
|
InputOption::VALUE_REQUIRED, |
80
|
|
|
'Package description' |
81
|
|
|
) |
82
|
|
|
->addOption( |
83
|
|
|
InputTransformer::KEY_KEYWORD, |
84
|
|
|
null, |
85
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
86
|
|
|
'Package keywords' |
87
|
|
|
) |
88
|
|
|
->addOption( |
89
|
|
|
InputTransformer::KEY_AUTHOR, |
90
|
|
|
null, |
91
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
92
|
|
|
'Package authors. Format "name[#email[#role]]' |
93
|
|
|
) |
94
|
|
|
->addOption( |
95
|
|
|
InputTransformer::KEY_PROVIDED_PACKAGE, |
96
|
|
|
null, |
97
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
98
|
|
|
'List of packages provided by this one. Ex : "package-name#version"' |
99
|
|
|
) |
100
|
|
|
->addOption( |
101
|
|
|
InputTransformer::KEY_SUGGESTED_PACKAGE, |
102
|
|
|
null, |
103
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
104
|
|
|
'List of packages suggested by this one. Ex : "package-name#description"' |
105
|
|
|
) |
106
|
|
|
->addOption( |
107
|
|
|
InputTransformer::KEY_SUPPORT, |
108
|
|
|
null, |
109
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
110
|
|
|
'List of package support urls. Ex : "type#url"' |
111
|
|
|
) |
112
|
|
|
->addOption( |
113
|
|
|
InputTransformer::KEY_AUTOLOAD_PSR0, |
114
|
|
|
null, |
115
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
116
|
|
|
'List of PSR-0 autoload. Ex : "namespace#path"' |
117
|
|
|
) |
118
|
|
|
->addOption( |
119
|
|
|
InputTransformer::KEY_AUTOLOAD_PSR4, |
120
|
|
|
null, |
121
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
122
|
|
|
'List of PSR-4 autoload. Ex : "namespace#path"' |
123
|
|
|
) |
124
|
|
|
->addOption( |
125
|
|
|
InputTransformer::KEY_AUTOLOAD_DEV_PSR0, |
126
|
|
|
null, |
127
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
128
|
|
|
'List of PSR-0 dev autoload. Ex : "namespace#path"' |
129
|
|
|
) |
130
|
|
|
->addOption( |
131
|
|
|
InputTransformer::KEY_AUTOLOAD_DEV_PSR4, |
132
|
|
|
null, |
133
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
134
|
|
|
'List of PSR-4 dev autoload. Ex : "namespace#path"' |
135
|
|
|
) |
136
|
|
|
->addOption( |
137
|
|
|
InputTransformer::KEY_REQUIRE, |
138
|
|
|
null, |
139
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
140
|
|
|
'List of required packages. Ex "vendor/package-name#~x.y"' |
141
|
|
|
) |
142
|
|
|
->addOption( |
143
|
|
|
InputTransformer::KEY_REQUIRE_DEV, |
144
|
|
|
null, |
145
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
146
|
|
|
'List of required dev packages. Ex "vendor/package-name#~x.y"' |
147
|
|
|
) |
148
|
|
|
->addOption( |
149
|
|
|
InputTransformer::KEY_SCRIPT, |
150
|
|
|
null, |
151
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
152
|
|
|
'List of scripts for the package. Ex : "script-name#command"' |
153
|
|
|
) |
154
|
|
|
; |
155
|
|
|
parent::configure(); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* {@inheritdoc} |
160
|
|
|
*/ |
161
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
162
|
|
|
{ |
163
|
|
|
$this->createConfiguration->run( |
164
|
|
|
new CreateConfigurationRequest( |
165
|
|
|
$this->loadConfiguration($input), |
166
|
|
|
$input->getArgument(self::ARGUMENT_CONFIGURATION_DEST_FOLDER), |
167
|
|
|
$this->loadTemplateConfiguration($input) |
168
|
|
|
) |
169
|
|
|
); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param InputInterface $input |
174
|
|
|
* |
175
|
|
|
* @return Configuration |
176
|
|
|
*/ |
177
|
|
|
protected function loadConfiguration(InputInterface $input) |
178
|
|
|
{ |
179
|
|
|
return $this->inputTransformer->fromCommandLine( |
180
|
|
|
[ |
181
|
|
|
InputTransformer::KEY_PACKAGE_NAME => $input->getArgument(InputTransformer::KEY_PACKAGE_NAME) |
182
|
|
|
] + $input->getOptions() |
183
|
|
|
); |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|