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
use crate::{
args::Args,
config::user::UserConfig,
git::{clone_into_folder, parse_to_git_url},
};
use anyhow::Result;
use std::{env, path::PathBuf, process::exit};
#[allow(clippy::or_fun_call)]
pub fn run(args: &Args, user_config: &UserConfig) -> Result<PathBuf> {
let repository_url = args
.profile
.as_ref()
.map(|profile_name| {
if let Some(profiles) = &user_config.profiles {
profiles.get(profile_name.as_str())
} else {
None
}
})
.flatten()
.or(args.git.as_deref().as_ref())
.map(|&url| parse_to_git_url(url));
if let Some(repository_url) = repository_url {
let repository_dir_path = env::current_dir()?.join(&args.name.as_ref().unwrap());
if repository_dir_path.exists() {
eprintln!(
"A folder named {:?} already exists!",
&args.name.as_ref().unwrap()
);
exit(1);
}
clone_into_folder(&repository_url, &repository_dir_path)?;
Ok(repository_dir_path)
} else {
unreachable!();
}
}