Skip to content

Commit

Permalink
add plugin_dir field to RepoSpec (#4017)
Browse files Browse the repository at this point in the history
  • Loading branch information
MLFlexer authored Jul 17, 2023
1 parent e048410 commit 94ab049
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lua-api-crates/plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use wezterm_dynamic::{FromDynamic, ToDynamic};
struct RepoSpec {
url: String,
component: String,
plugin_dir: PathBuf,
}

/// Given a URL, generate a string that can be used as a directory name.
Expand Down Expand Up @@ -55,7 +56,13 @@ impl RepoSpec {
anyhow::bail!("invalid repo spec {url}");
}

Ok(Self { url, component })
let plugin_dir = RepoSpec::plugins_dir().join(&component);

Ok(Self {
url,
component,
plugin_dir,
})
}

fn load_from_dir(path: PathBuf) -> anyhow::Result<Self> {
Expand All @@ -66,12 +73,18 @@ impl RepoSpec {
.ok_or_else(|| anyhow!("{path:?} isn't unicode"))?
.to_string();

let plugin_dir = RepoSpec::plugins_dir().join(&component);

let repo = Repository::open(&path)?;
let remote = get_remote(&repo)?.ok_or_else(|| anyhow!("no remotes!?"))?;
let url = remote.url();
if let Some(url) = url {
let url = url.to_string();
return Ok(Self { component, url });
return Ok(Self {
component,
url,
plugin_dir,
});
}
anyhow::bail!("Unable to create a complete RepoSpec for repo at {path:?}");
}
Expand Down

0 comments on commit 94ab049

Please sign in to comment.