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