1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
//! ref: composer/src/Composer/Command/InstallCommand.php
use anyhow::Result;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::input::InputInterface;
use shirabe_external_packages::symfony::console::output::OutputInterface;
use shirabe_php_shim::PhpMixed;
use std::cell::RefCell;
use std::rc::Rc;
use crate::advisory::Auditor;
use crate::command::BaseCommand;
use crate::command::BaseCommandData;
use crate::command::base_command::base_command_initialize;
use crate::console::input::InputArgument;
use crate::console::input::InputOption;
use crate::installer::Installer;
use crate::io::IOInterfaceImmutable;
use crate::plugin::CommandEvent;
use crate::plugin::PluginEvents;
use crate::util::HttpDownloader;
#[derive(Debug)]
pub struct InstallCommand {
base_command_data: BaseCommandData,
}
impl Default for InstallCommand {
fn default() -> Self {
Self::new()
}
}
impl InstallCommand {
pub fn new() -> Self {
let command = InstallCommand {
base_command_data: BaseCommandData::new(None),
};
command
.configure()
.expect("InstallCommand::configure uses static, valid metadata");
command
}
}
impl Command for InstallCommand {
fn configure(&self) -> anyhow::Result<()> {
// TODO(cli-completion): suggest_prefer_install() for `prefer-install` option
self.set_name("install")?;
self.set_aliases(vec!["i".to_string()])?;
self.set_description("Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json");
self.set_definition(&[
InputOption::new("prefer-source", None, Some(InputOption::VALUE_NONE), "Forces installation from package sources when possible, including VCS information.", None).unwrap().into(),
InputOption::new("prefer-dist", None, Some(InputOption::VALUE_NONE), "Forces installation from package dist (default behavior).", None).unwrap().into(),
InputOption::new("prefer-install", None, Some(InputOption::VALUE_REQUIRED), "Forces installation from package dist|source|auto (auto chooses source for dev versions, dist for the rest).", None).unwrap().into(),
InputOption::new("dry-run", None, Some(InputOption::VALUE_NONE), "Outputs the operations but will not execute anything (implicitly enables --verbose).", None).unwrap().into(),
InputOption::new("download-only", None, Some(InputOption::VALUE_NONE), "Download only, do not install packages.", None).unwrap().into(),
InputOption::new("dev", None, Some(InputOption::VALUE_NONE), "DEPRECATED: Enables installation of require-dev packages (enabled by default, only present for BC).", None).unwrap().into(),
InputOption::new("no-suggest", None, Some(InputOption::VALUE_NONE), "DEPRECATED: This flag does not exist anymore.", None).unwrap().into(),
InputOption::new("no-dev", None, Some(InputOption::VALUE_NONE), "Disables installation of require-dev packages.", None).unwrap().into(),
InputOption::new("no-security-blocking", None, Some(InputOption::VALUE_NONE), "Allows installing packages with security advisories or that are abandoned (can also be set via the COMPOSER_NO_SECURITY_BLOCKING=1 env var). Only applies when no lock file is present.", None).unwrap().into(),
InputOption::new("no-autoloader", None, Some(InputOption::VALUE_NONE), "Skips autoloader generation", None).unwrap().into(),
InputOption::new("no-progress", None, Some(InputOption::VALUE_NONE), "Do not output download progress.", None).unwrap().into(),
InputOption::new("no-install", None, Some(InputOption::VALUE_NONE), "Do not use, only defined here to catch misuse of the install command.", None).unwrap().into(),
InputOption::new("audit", None, Some(InputOption::VALUE_NONE), "Run an audit after installation is complete.", None).unwrap().into(),
InputOption::new("audit-format", None, Some(InputOption::VALUE_REQUIRED), "Audit output format. Must be \"table\", \"plain\", \"json\", or \"summary\".", Some(PhpMixed::String(Auditor::FORMAT_SUMMARY.to_string()))).unwrap().into(),
InputOption::new("verbose", Some(PhpMixed::String("v|vv|vvv".to_string())), Some(InputOption::VALUE_NONE), "Shows more details including new commits pulled in when updating packages.", None).unwrap().into(),
InputOption::new("optimize-autoloader", Some(PhpMixed::String("o".to_string())), Some(InputOption::VALUE_NONE), "Optimize autoloader during autoloader dump", None).unwrap().into(),
InputOption::new("classmap-authoritative", Some(PhpMixed::String("a".to_string())), Some(InputOption::VALUE_NONE), "Autoload classes from the classmap only. Implicitly enables `--optimize-autoloader`.", None).unwrap().into(),
InputOption::new("apcu-autoloader", None, Some(InputOption::VALUE_NONE), "Use APCu to cache found/not-found classes.", None).unwrap().into(),
InputOption::new("apcu-autoloader-prefix", None, Some(InputOption::VALUE_REQUIRED), "Use a custom prefix for the APCu autoloader cache. Implicitly enables --apcu-autoloader", None).unwrap().into(),
InputOption::new("ignore-platform-req", None, Some(InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY), "Ignore a specific platform requirement (php & ext- packages).", None).unwrap().into(),
InputOption::new("ignore-platform-reqs", None, Some(InputOption::VALUE_NONE), "Ignore all platform requirements (php & ext- packages).", None).unwrap().into(),
InputArgument::new("packages", Some(InputArgument::IS_ARRAY | InputArgument::OPTIONAL), "Should not be provided, use composer require instead to add a given package to composer.json.", None).unwrap().into(),
]);
self.set_help(
"The <info>install</info> command reads the composer.lock file from\n\
the current directory, processes it, and downloads and installs all the\n\
libraries and dependencies outlined in that file. If the file does not\n\
exist it will look for composer.json and do the same.\n\n\
<info>shirabe install</info>\n\n\
Read more at https://getcomposer.org/doc/03-cli.md#install-i",
);
Ok(())
}
fn execute(
&self,
input: Rc<RefCell<dyn InputInterface>>,
output: Rc<RefCell<dyn OutputInterface>>,
) -> anyhow::Result<i64> {
let io = self.get_io().clone();
if input.borrow().get_option("dev")?.as_bool().unwrap_or(false) {
io.write_error("<warning>You are using the deprecated option \"--dev\". It has no effect and will break in Composer 3.</warning>");
}
if input
.borrow()
.get_option("no-suggest")?
.as_bool()
.unwrap_or(false)
{
io.write_error("<warning>You are using the deprecated option \"--no-suggest\". It has no effect and will break in Composer 3.</warning>");
}
let args = input.borrow().get_argument("packages")?;
let args_vec: Vec<String> = args
.as_list()
.map(|l| {
l.iter()
.filter_map(|v| v.as_string().map(|s| s.to_string()))
.collect()
})
.unwrap_or_default();
if !args_vec.is_empty() {
io.write_error(&format!(
"<error>Invalid argument {}. Use \"composer require {}\" instead to add packages to your composer.json.</error>",
args_vec.join(" "),
args_vec.join(" ")
));
return Ok(1);
}
if input
.borrow()
.get_option("no-install")?
.as_bool()
.unwrap_or(false)
{
io.write_error("<error>Invalid option \"--no-install\". Use \"composer update --no-install\" instead if you are trying to update the composer.lock file.</error>");
return Ok(1);
}
let composer_handle = self.require_composer(None, None)?;
let composer = crate::command::composer_full_mut(&composer_handle);
if !composer.get_locker().borrow_mut().is_locked() && !HttpDownloader::is_curl_enabled() {
io.write_error("<warning>Composer is operating significantly slower than normal because you do not have the PHP curl extension enabled.</warning>");
}
// TODO(plugin): dispatch CommandEvent
let command_event =
CommandEvent::new(PluginEvents::COMMAND, "install", input.clone(), output);
composer
.get_event_dispatcher()
.borrow_mut()
.dispatch(Some(command_event.get_name()), None);
let mut install = Installer::create(io.clone(), &composer_handle);
let config = composer.get_config();
let (prefer_source, prefer_dist) =
self.get_preferred_install_options(&config.borrow(), input.clone(), false)?;
let optimize = input
.borrow()
.get_option("optimize-autoloader")?
.as_bool()
.unwrap_or(false)
|| config
.borrow_mut()
.get("optimize-autoloader")
.as_bool()
.unwrap_or(false);
let authoritative = input
.borrow()
.get_option("classmap-authoritative")?
.as_bool()
.unwrap_or(false)
|| config
.borrow_mut()
.get("classmap-authoritative")
.as_bool()
.unwrap_or(false);
let apcu_prefix = input
.borrow()
.get_option("apcu-autoloader-prefix")?
.as_string()
.map(|s| s.to_string());
let apcu = apcu_prefix.is_some()
|| input
.borrow()
.get_option("apcu-autoloader")?
.as_bool()
.unwrap_or(false)
|| config
.borrow_mut()
.get("apcu-autoloader")
.as_bool()
.unwrap_or(false);
composer
.get_installation_manager()
.borrow_mut()
.set_output_progress(
!input
.borrow()
.get_option("no-progress")?
.as_bool()
.unwrap_or(false),
);
install
.set_dry_run(
input
.borrow()
.get_option("dry-run")?
.as_bool()
.unwrap_or(false),
)
.set_download_only(
input
.borrow()
.get_option("download-only")?
.as_bool()
.unwrap_or(false),
)
.set_verbose(
input
.borrow()
.get_option("verbose")?
.as_bool()
.unwrap_or(false),
)
.set_prefer_source(prefer_source)
.set_prefer_dist(prefer_dist)
.set_dev_mode(
!input
.borrow()
.get_option("no-dev")?
.as_bool()
.unwrap_or(false),
)
.set_dump_autoloader(
!input
.borrow()
.get_option("no-autoloader")?
.as_bool()
.unwrap_or(false),
)
.set_optimize_autoloader(optimize)
.set_class_map_authoritative(authoritative)
.set_apcu_autoloader(apcu, apcu_prefix.clone())
.set_platform_requirement_filter(self.get_platform_requirement_filter(input.clone())?)
.set_audit_config(
self.create_audit_config(&mut composer.get_config().borrow_mut(), input.clone())?,
)
.set_error_on_audit(
input
.borrow()
.get_option("audit")?
.as_bool()
.unwrap_or(false),
);
if input
.borrow()
.get_option("no-plugins")?
.as_bool()
.unwrap_or(false)
{
install.disable_plugins();
}
install.run()
}
fn initialize(
&self,
input: Rc<RefCell<dyn InputInterface>>,
output: Rc<RefCell<dyn OutputInterface>>,
) -> anyhow::Result<()> {
base_command_initialize(self, input, output)
}
shirabe_external_packages::delegate_command_trait_impls_to_inner!(base_command_data);
}
impl BaseCommand for InstallCommand {
fn command_data(
&self,
) -> &shirabe_external_packages::symfony::console::command::command::CommandData {
self.base_command_data.command_data()
}
crate::delegate_base_command_trait_impls_to_inner!(base_command_data);
}
|