Skip to main content

multiversx_sc_meta/cmd/template/
repo_source.rs

1use 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 async 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(version, temp_dir_path).await)
17    }
18
19    pub fn from_local_path(repo_local_path: impl AsRef<Path>) -> Self {
20        RepoSource::LocalPath(repo_local_path.as_ref().to_path_buf())
21    }
22
23    pub fn repo_path(&self) -> PathBuf {
24        match self {
25            RepoSource::Downloaded(repo_temp_download) => {
26                repo_temp_download.repository_temp_dir_path()
27            }
28            RepoSource::LocalPath(local_path) => local_path.clone(),
29        }
30    }
31}