1use std::path::PathBuf;
2
3use eyre::Result;
4use lux_lib::{config::Config, operations::Download, progress::MultiProgress, rockspec::Rockspec};
5
6use crate::unpack::UnpackRemote;
7
8pub async fn fetch_remote(data: UnpackRemote, config: Config) -> Result<()> {
9 let package_req = data.package_req;
10 let progress = MultiProgress::new(&config);
11 let bar = progress.map(MultiProgress::new_bar);
12
13 let rockspec = Download::new(&package_req, &config, &bar)
14 .download_rockspec()
15 .await?
16 .rockspec;
17
18 let destination = data.path.unwrap_or_else(|| {
19 PathBuf::from(format!("{}-{}", &rockspec.package(), &rockspec.version()))
20 });
21 lux_lib::operations::FetchSrc::new(destination.clone().as_path(), &rockspec, &config, &bar)
22 .fetch()
23 .await?;
24
25 let rock_source = rockspec.source().current_platform();
26 let build_dir = rock_source
27 .unpack_dir
28 .as_ref()
29 .map(|path| destination.join(path))
30 .unwrap_or_else(|| destination);
31
32 bar.map(|b| {
33 b.finish_with_message(format!(
34 "
35You may now enter the following directory:
36{}
37and type `lux build` to build.
38 ",
39 build_dir.as_path().display()
40 ))
41 });
42
43 Ok(())
44}