Skip to content

Commit

Permalink
repo: define RepoSource to support local path
Browse files Browse the repository at this point in the history
  • Loading branch information
zjp-CN committed Nov 3, 2024
1 parent 6cbc556 commit 4ecf071
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() -> Result<()> {

for user_repo in &list {
let _span = error_span!("list", user_repo).entered();
match repo::Repo::new(user_repo) {
match repo::Repo::new(user_repo, repo::RepoSource::Github) {
Ok(val) => match val.output() {
Ok(output) => outputs.push(output),
Err(err) => error!(?err),
Expand Down
26 changes: 18 additions & 8 deletions src/repo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,34 @@ use testcases::PkgTests;
mod output;
mod testcases;

pub enum RepoSource {
Github,
Local(Utf8PathBuf),
}

#[derive(Debug)]
#[allow(unused)]
pub struct Repo {
user: String,
repo: String,
pub user: String,
pub repo: String,
// repo root
dir: Utf8PathBuf,
cargo_tomls: Vec<Utf8PathBuf>,
workspaces: Workspaces,
pub dir: Utf8PathBuf,
pub cargo_tomls: Vec<Utf8PathBuf>,
pub workspaces: Workspaces,
}

impl Repo {
pub fn new(user_repo: &str) -> Result<Repo> {
pub fn new(user_repo: &str, src: RepoSource) -> Result<Repo> {
let v: Vec<_> = user_repo.split("/").collect();
let user = v[0].to_owned();
let repo = v[1].to_owned();

let dir = git_clone(&user, &repo)?;
let dir = match src {
RepoSource::Github => git_clone(&user, &repo)?,
RepoSource::Local(p) => {
ensure!(p.is_dir(), "{p} is not a directory");
p.canonicalize_utf8()?
}
};

let mut cargo_tomls = get_cargo_tomls_recursively(&dir);
cargo_tomls.sort_unstable();
Expand Down

0 comments on commit 4ecf071

Please sign in to comment.