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