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\WriteConfiguration; |
10
|
|
|
use Yoanm\ComposerConfigManager\Domain\Model\Configuration; |
11
|
|
|
use Yoanm\ComposerConfigManager\Infrastructure\Command\Transformer\InputTransformer; |
12
|
|
|
|
13
|
|
|
class WriteConfigurationCommand extends Command |
14
|
|
|
{ |
15
|
|
|
const NAME = 'configuration:write'; |
16
|
|
|
|
17
|
|
|
/** @var InputTransformer */ |
18
|
|
|
private $inputTransformer; |
19
|
|
|
/** @var WriteConfiguration */ |
20
|
|
|
private $writeConfiguration; |
21
|
|
|
|
22
|
|
|
public function __construct( |
23
|
|
|
InputTransformer $inputTransformer, |
24
|
|
|
WriteConfiguration $writeConfiguration |
25
|
|
|
) { |
26
|
|
|
parent::__construct(self::NAME); |
27
|
|
|
|
28
|
|
|
$this->inputTransformer = $inputTransformer; |
29
|
|
|
$this->writeConfiguration = $writeConfiguration; |
30
|
|
|
} |
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
protected function configure() |
35
|
|
|
{ |
36
|
|
|
$this |
37
|
|
|
->setDescription('Will create or update a composer configuration file') |
38
|
|
|
->addArgument( |
39
|
|
|
InputTransformer::ARGUMENT_PACKAGE_NAME, |
40
|
|
|
InputArgument::REQUIRED, |
41
|
|
|
'Name for the composer package' |
42
|
|
|
) |
43
|
|
|
->addArgument( |
44
|
|
|
InputTransformer::ARGUMENT_CONFIGURATION_DEST_FOLDER, |
45
|
|
|
InputArgument::OPTIONAL, |
46
|
|
|
'Configuration file destination folder', |
47
|
|
|
'.' |
48
|
|
|
) |
49
|
|
|
->addOption( |
50
|
|
|
InputTransformer::OPTION_TYPE, |
51
|
|
|
null, |
52
|
|
|
InputOption::VALUE_REQUIRED, |
53
|
|
|
'Package type. Ex : "library" / "project"', |
54
|
|
|
Configuration::DEFAULT_TYPE |
55
|
|
|
) |
56
|
|
|
->addOption( |
57
|
|
|
InputTransformer::OPTION_LICENSE, |
58
|
|
|
null, |
59
|
|
|
InputOption::VALUE_REQUIRED, |
60
|
|
|
'Package license type', |
61
|
|
|
Configuration::DEFAULT_LICENSE |
62
|
|
|
) |
63
|
|
|
->addOption( |
64
|
|
|
InputTransformer::OPTION_PACKAGE_VERSION, |
65
|
|
|
null, |
66
|
|
|
InputOption::VALUE_REQUIRED, |
67
|
|
|
'Package version number. Ex : "X.Y.Z"', |
68
|
|
|
Configuration::DEFAULT_VERSION |
69
|
|
|
) |
70
|
|
|
->addOption( |
71
|
|
|
InputTransformer::OPTION_DESCRIPTION, |
72
|
|
|
null, |
73
|
|
|
InputOption::VALUE_REQUIRED, |
74
|
|
|
'Package description' |
75
|
|
|
) |
76
|
|
|
->addOption( |
77
|
|
|
InputTransformer::OPTION_KEYWORD, |
78
|
|
|
null, |
79
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
80
|
|
|
'Package keywords' |
81
|
|
|
) |
82
|
|
|
->addOption( |
83
|
|
|
InputTransformer::OPTION_AUTHOR, |
84
|
|
|
null, |
85
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
86
|
|
|
'Package authors. Format "name[#email[#role]]' |
87
|
|
|
) |
88
|
|
|
->addOption( |
89
|
|
|
InputTransformer::OPTION_PROVIDED_PACKAGE, |
90
|
|
|
null, |
91
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
92
|
|
|
'List of packages provided by this one. Ex : "package-name#version"' |
93
|
|
|
) |
94
|
|
|
->addOption( |
95
|
|
|
InputTransformer::OPTION_SUGGESTED_PACKAGE, |
96
|
|
|
null, |
97
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
98
|
|
|
'List of packages suggested by this one. Ex : "package-name#description"' |
99
|
|
|
) |
100
|
|
|
->addOption( |
101
|
|
|
InputTransformer::OPTION_SUPPORT, |
102
|
|
|
null, |
103
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
104
|
|
|
'List of package support urls. Ex : "type#url"' |
105
|
|
|
) |
106
|
|
|
->addOption( |
107
|
|
|
InputTransformer::OPTION_AUTOLOAD_PSR0, |
108
|
|
|
null, |
109
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
110
|
|
|
'List of package PSR-0 autoload. Ex : "namespace#path"' |
111
|
|
|
) |
112
|
|
|
->addOption( |
113
|
|
|
InputTransformer::OPTION_AUTOLOAD_PSR4, |
114
|
|
|
null, |
115
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
116
|
|
|
'List of package PSR-4 autoload. Ex : "namespace#path"' |
117
|
|
|
) |
118
|
|
|
->addOption( |
119
|
|
|
InputTransformer::OPTION_AUTOLOAD_DEV_PSR0, |
120
|
|
|
null, |
121
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
122
|
|
|
'List of packages PSR-0 dev autoload. Ex : "namespace#path"' |
123
|
|
|
) |
124
|
|
|
->addOption( |
125
|
|
|
InputTransformer::OPTION_AUTOLOAD_DEV_PSR4, |
126
|
|
|
null, |
127
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
128
|
|
|
'List of package PSR-4 dev autoload. Ex : "namespace#path"' |
129
|
|
|
) |
130
|
|
|
->addOption( |
131
|
|
|
InputTransformer::OPTION_REQUIRE, |
132
|
|
|
null, |
133
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
134
|
|
|
'List of required packages. Ex "vendor/package-name#~x.y"' |
135
|
|
|
) |
136
|
|
|
->addOption( |
137
|
|
|
InputTransformer::OPTION_REQUIRE_DEV, |
138
|
|
|
null, |
139
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
140
|
|
|
'List of required dev packages. Ex "vendor/package-name#~x.y"' |
141
|
|
|
) |
142
|
|
|
->addOption( |
143
|
|
|
InputTransformer::OPTION_SCRIPT, |
144
|
|
|
null, |
145
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
146
|
|
|
'List of scripts for the package. Ex : "script-name#command"' |
147
|
|
|
) |
148
|
|
|
; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* {@inheritdoc} |
153
|
|
|
*/ |
154
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
155
|
|
|
{ |
156
|
|
|
$writeRequest = $this->inputTransformer->fromCommandLine($input->getArguments(), $input->getOptions()); |
157
|
|
|
|
158
|
|
|
$this->writeConfiguration->run($writeRequest); |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|