drt_sc_meta/cmd/template/
repo_source.rs1use std::{
2 fs,
3 path::{Path, PathBuf},
4};
5
6use super::{RepoTempDownload, RepoVersion};
7
8pub enum RepoSource {
9 Downloaded(RepoTempDownload),
10 LocalPath(PathBuf),
11}
12
13impl RepoSource {
14 pub fn download_from_github(version: RepoVersion, temp_dir_path: PathBuf) -> Self {
15 fs::create_dir_all(&temp_dir_path).unwrap();
16 RepoSource::Downloaded(RepoTempDownload::download_from_github(
17 version,
18 temp_dir_path,
19 ))
20 }
21
22 pub fn from_local_path(repo_local_path: impl AsRef<Path>) -> Self {
23 RepoSource::LocalPath(repo_local_path.as_ref().to_path_buf())
24 }
25
26 pub fn repo_path(&self) -> PathBuf {
27 match self {
28 RepoSource::Downloaded(repo_temp_download) => {
29 repo_temp_download.repository_temp_dir_path()
30 },
31 RepoSource::LocalPath(local_path) => local_path.clone(),
32 }
33 }
34}