Skip to main content

docsrs_cli/config/load/
paths.rs

1//! `config path`: agent-readable inventory of resolved storage locations.
2
3use std::path::{Path, PathBuf};
4
5use serde::{Deserialize, Serialize};
6
7use crate::config::constants::CONFIG_FILE_NAME;
8use crate::config::path_source::PathSource;
9
10use super::Config;
11
12/// Path inventory for `config path` (agent-readable).
13#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
14pub struct ConfigPathData {
15    /// Resolved config directory, if any.
16    pub config_dir: Option<String>,
17    /// Layer that resolved the config directory.
18    pub config_source: PathSource,
19    /// Absolute `config.toml` path (even if the file does not exist yet).
20    pub config_file: Option<String>,
21    /// Whether `config.toml` is present on disk.
22    pub config_file_exists: bool,
23    /// Whether load applied TOML keys (same as exists for normal runs).
24    pub config_toml_loaded: bool,
25    /// Resolved cache directory, if any.
26    pub cache_dir: Option<String>,
27    /// Layer that resolved the cache directory.
28    pub cache_source: PathSource,
29    /// Product does not use `.env` at runtime after install.
30    pub dotenv_runtime: bool,
31    /// Product stores no API keys; keyring/cloud secret layers are unused.
32    pub secrets_layers: &'static str,
33}
34
35/// Build path inventory from a loaded [`Config`].
36pub fn config_path_data(cfg: &Config) -> ConfigPathData {
37    let config_file = cfg.config_file_path();
38    let exists = config_file.as_ref().is_some_and(|p| p.is_file());
39    ConfigPathData {
40        config_dir: cfg.config_dir.as_ref().map(|p| p.display().to_string()),
41        config_source: cfg.config_path_source,
42        config_file: config_file.as_ref().map(|p| p.display().to_string()),
43        config_file_exists: exists,
44        config_toml_loaded: cfg.config_toml_loaded,
45        cache_dir: cfg.cache_dir.as_ref().map(|p| p.display().to_string()),
46        cache_source: cfg.cache_path_source,
47        dotenv_runtime: false,
48        secrets_layers: "none (public HTTP only; no API keys)",
49    }
50}
51
52/// Ensure `path` is under a directory (used by tests / path display).
53pub fn config_toml_under(dir: &Path) -> PathBuf {
54    dir.join(CONFIG_FILE_NAME)
55}