1use std::path::PathBuf;
2use std::process::Command;
3use crate::cli::{CloneArgs, CloneSource};
4use crate::std_command_ext::ExecuteCommand;
5use crate::tool::dir_copier::deep_copy;
6
7fn clone_git(url: String, branch: String, destination: PathBuf) -> anyhow::Result<()> {
8 let mut command = Command::new("git");
9 command.arg("clone");
10 command.arg(url);
11 command.arg("--single-branch");
12 command.arg("--branch");
13 command.arg(branch);
14 command.arg(destination);
15
16 command.execute(true)?;
17
18 Ok(())
19}
20
21fn clone_file_system(from_path: PathBuf, destination: PathBuf) -> anyhow::Result<()> {
22 deep_copy(from_path, destination)?;
23
24 Ok(())
25}
26
27pub fn clone(clone_args: CloneArgs) -> anyhow::Result<()> {
28 log::info!("Cloning project from {:?} to {:?}", clone_args.source, clone_args.path);
29
30 match clone_args.source {
31 CloneSource::Git { url, branch } => clone_git(url, branch, clone_args.path)?,
32 CloneSource::FileSystem { from } => clone_file_system(from, clone_args.path)?,
33 }
34
35 log::info!("PROJECT CLONED SUCCESSFULLY");
36 Ok(())
37}