Skip to content

Commit

Permalink
check for brew installation of templates
Browse files Browse the repository at this point in the history
Signed-off-by: Kate Goldenring <[email protected]>
  • Loading branch information
kate-goldenring committed May 12, 2023
1 parent 768d128 commit da73b0a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions crates/plugins/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ impl PluginStore {
}

pub fn try_default() -> Result<Self> {
if let Ok(brew_prefix) = std::env::var("HOMEBREW_PREFIX") {
let plugins_dir = Path::new(&brew_prefix).join("var/spin/plugins");

if plugins_dir.exists() && plugins_dir.is_dir() {
println!("Path to brew plugins exists");
return Ok(Self::new(plugins_dir));
// TODO: check if they also have plugins in non-brew default dir and warn
}
}
let data_dir = match std::env::var("TEST_PLUGINS_DIRECTORY") {
Ok(test_dir) => PathBuf::from(test_dir),
Err(_) => dirs::data_local_dir()
Expand Down
10 changes: 10 additions & 0 deletions crates/templates/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ impl TemplateStore {
}

pub(crate) fn try_default() -> anyhow::Result<Self> {
if let Ok(brew_prefix) = std::env::var("HOMEBREW_PREFIX") {
let templates_dir = Path::new(&brew_prefix).join("var/spin/templates");

if templates_dir.exists() && templates_dir.is_dir() {
println!("Path to brew templates exists");
return Ok(Self::new(templates_dir));
// TODO: check if they also have templates in non-brew default dir and warn
}
}

let data_dir = dirs::data_local_dir()
.or_else(|| dirs::home_dir().map(|p| p.join(".spin")))
.ok_or_else(|| anyhow!("Unable to get local data directory or home directory"))?;
Expand Down

0 comments on commit da73b0a

Please sign in to comment.