pub struct SpnPaths { /* private fields */ }Expand description
Centralized path management for the ~/.spn directory structure.
Provides type-safe access to all paths used by spn-cli, spn-daemon, and other tools in the SuperNovae ecosystem.
Implementations§
Source§impl SpnPaths
impl SpnPaths
Sourcepub fn new() -> Result<Self, PathError>
pub fn new() -> Result<Self, PathError>
Create paths rooted at the default location (~/.spn).
Returns an error if the HOME directory is not available.
§Example
use spn_client::SpnPaths;
let paths = SpnPaths::new()?;
println!("Root: {:?}", paths.root());Sourcepub fn with_root(root: PathBuf) -> Self
pub fn with_root(root: PathBuf) -> Self
Create paths with a custom root directory.
Useful for testing or custom installations.
§Example
use spn_client::SpnPaths;
use std::path::PathBuf;
let paths = SpnPaths::with_root(PathBuf::from("/tmp/spn-test"));
assert_eq!(paths.root().to_str().unwrap(), "/tmp/spn-test");Sourcepub fn bin_dir(&self) -> PathBuf
pub fn bin_dir(&self) -> PathBuf
Binary directory (~/.spn/bin).
Contains symlinks or stubs for nika, novanet, etc.
Sourcepub fn packages_dir(&self) -> PathBuf
pub fn packages_dir(&self) -> PathBuf
Packages directory (~/.spn/packages).
Structure: packages/@scope/name/version/
Sourcepub fn cache_dir(&self) -> PathBuf
pub fn cache_dir(&self) -> PathBuf
Cache directory (~/.spn/cache).
Contains downloaded tarballs and temporary files.
Sourcepub fn tarballs_dir(&self) -> PathBuf
pub fn tarballs_dir(&self) -> PathBuf
Tarballs cache directory (~/.spn/cache/tarballs).
Sourcepub fn registry_dir(&self) -> PathBuf
pub fn registry_dir(&self) -> PathBuf
Registry cache directory (~/.spn/registry).
Contains cached package index data.
Sourcepub fn config_file(&self) -> PathBuf
pub fn config_file(&self) -> PathBuf
Global configuration file (~/.spn/config.toml).
Sourcepub fn secrets_file(&self) -> PathBuf
pub fn secrets_file(&self) -> PathBuf
Secrets file (~/.spn/secrets.env).
Alternative to OS keychain for storing API keys.
Sourcepub fn socket_file(&self) -> PathBuf
pub fn socket_file(&self) -> PathBuf
Daemon socket file (~/.spn/daemon.sock).
Sourcepub fn state_file(&self) -> PathBuf
pub fn state_file(&self) -> PathBuf
State file (~/.spn/state.json).
Tracks installed packages and their versions.
Sourcepub fn package_dir(&self, name: &str, version: &str) -> PathBuf
pub fn package_dir(&self, name: &str, version: &str) -> PathBuf
Get the path for a specific package version.
§Arguments
name- Package name (e.g., “@workflows/code-review”)version- Package version (e.g., “1.0.0”)
§Example
use spn_client::SpnPaths;
use std::path::PathBuf;
let paths = SpnPaths::with_root(PathBuf::from("/home/user/.spn"));
let pkg_path = paths.package_dir("@workflows/code-review", "1.0.0");
assert!(pkg_path.to_string_lossy().contains("@workflows"));Sourcepub fn ensure_dirs(&self) -> Result<(), PathError>
pub fn ensure_dirs(&self) -> Result<(), PathError>
Ensure all required directories exist.
Creates the following directories if they don’t exist:
- ~/.spn/
- ~/.spn/bin/
- ~/.spn/packages/
- ~/.spn/cache/
- ~/.spn/cache/tarballs/
- ~/.spn/registry/
§Example
use spn_client::SpnPaths;
let paths = SpnPaths::new()?;
paths.ensure_dirs()?;