Skip to main content

vs_core/service/
cd.rs

1//! Services for resolving directories used by `vs cd`.
2
3use crate::{App, CoreError};
4
5impl App {
6    /// Returns the active home directory path.
7    pub fn home_dir(&self) -> String {
8        self.home().display().to_string()
9    }
10
11    /// Prints the active runtime directory for a tool.
12    pub fn cd_path(&self, plugin_name: &str) -> Result<String, CoreError> {
13        let current = self
14            .current_tool(plugin_name)?
15            .ok_or_else(|| CoreError::InactiveTool(plugin_name.to_string()))?;
16        Ok(self.effective_runtime_dir(&current).display().to_string())
17    }
18
19    /// Returns the local plugin source directory.
20    pub fn plugin_dir(&self, plugin_name: &str) -> Result<String, CoreError> {
21        let entry = self.resolve_registry_entry(plugin_name)?;
22        let entry = self.materialize_plugin_entry(&entry)?;
23        Ok(self
24            .normalize_source_path(&entry.source)
25            .display()
26            .to_string())
27    }
28}