Skip to main content

harmont_cli/plugin/
paths.rs

1//! Filesystem locations the plugin host inspects.
2
3// `#[must_use]` would be noise on these three single-line `Option<PathBuf>`
4// helpers — the names already describe the only thing the caller can do
5// with the return value.
6#![allow(clippy::must_use_candidate)]
7// The single test asserts the path resolved on this host; if config_dir
8// can't produce anything, the test environment is the bug.
9#![cfg_attr(test, allow(clippy::expect_used))]
10
11use std::path::PathBuf;
12
13/// `~/.config/harmont/plugins/` (or the platform's XDG equivalent).
14/// User-global plugins live here.
15pub fn user_plugins_dir() -> Option<PathBuf> {
16    dirs::config_dir().map(|p| p.join("harmont").join("plugins"))
17}
18
19/// `<cwd>/.harmont/plugins/`. Project-local plugins live here.
20pub fn project_plugins_dir() -> Option<PathBuf> {
21    std::env::current_dir()
22        .ok()
23        .map(|p| p.join(".harmont").join("plugins"))
24}
25
26/// Where `hm plugin install` writes plugins.
27pub fn install_dir() -> Option<PathBuf> {
28    user_plugins_dir()
29}
30
31#[cfg(test)]
32mod tests {
33    use super::*;
34
35    #[test]
36    fn user_plugins_dir_resolves() {
37        let p = user_plugins_dir().expect("config dir resolves");
38        assert!(p.ends_with("harmont/plugins"));
39    }
40}