mirror of
https://github.com/tealdeer-rs/tealdeer.git
synced 2026-08-20 15:14:18 +02:00
Bring back path source for cache directory
This commit is contained in:
parent
33f0f108d8
commit
afbdfa6746
3 changed files with 31 additions and 14 deletions
|
|
@ -240,9 +240,15 @@ pub struct UpdatesConfig {
|
|||
pub auto_update_interval: Duration,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct PathWithSource {
|
||||
pub path: PathBuf,
|
||||
pub source: PathSource,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct DirectoriesConfig {
|
||||
pub cache_dir: PathBuf,
|
||||
pub cache_dir: PathWithSource,
|
||||
pub custom_pages_dir: Option<PathBuf>,
|
||||
}
|
||||
|
||||
|
|
@ -290,13 +296,22 @@ impl Config {
|
|||
// overridden using an env variable. This is deprecated and will be
|
||||
// phased out in the future.
|
||||
eprintln!("Warning: The ${} env variable is deprecated, use the `cache_dir` option in the config file instead.", cache_dir_env_var);
|
||||
PathBuf::from(env_var)
|
||||
PathWithSource {
|
||||
path: PathBuf::from(env_var),
|
||||
source: PathSource::EnvVar,
|
||||
}
|
||||
} else if let Some(config_value) = raw_config.directories.cache_dir {
|
||||
// If the user explicitly configured a cache directory, use that.
|
||||
config_value
|
||||
PathWithSource {
|
||||
path: config_value,
|
||||
source: PathSource::ConfigFile,
|
||||
}
|
||||
} else if let Ok(default_dir) = get_app_root(AppDataType::UserCache, &crate::APP_INFO) {
|
||||
// Otherwise, fall back to the default user cache directory.
|
||||
default_dir
|
||||
PathWithSource {
|
||||
path: default_dir,
|
||||
source: PathSource::OsConvention,
|
||||
}
|
||||
} else {
|
||||
// If everything fails, give up
|
||||
bail!("Could not determine user cache directory");
|
||||
|
|
|
|||
12
src/main.rs
12
src/main.rs
|
|
@ -161,9 +161,13 @@ fn show_paths(config: &Config) {
|
|||
|e| format!("[Error: {}]", e),
|
||||
|(path, _)| path.display().to_string(),
|
||||
);
|
||||
let cache_dir = config.directories.cache_dir.display();
|
||||
let cache_dir = format!(
|
||||
"{} ({})",
|
||||
config.directories.cache_dir.path.display(),
|
||||
config.directories.cache_dir.source
|
||||
);
|
||||
let pages_dir = {
|
||||
let mut path = config.directories.cache_dir.clone();
|
||||
let mut path = config.directories.cache_dir.path.clone();
|
||||
path.push(TLDR_PAGES_DIR);
|
||||
path.push(""); // Trailing path separator
|
||||
path.display().to_string()
|
||||
|
|
@ -328,8 +332,8 @@ fn main() {
|
|||
}
|
||||
|
||||
// Initialize cache
|
||||
let cache =
|
||||
Cache::new(ARCHIVE_URL, platform, &config.directories.cache_dir).unwrap_or_else(|e| {
|
||||
let cache = Cache::new(ARCHIVE_URL, platform, &config.directories.cache_dir.path)
|
||||
.unwrap_or_else(|e| {
|
||||
print_error(enable_styles, &e.context("Could not initialize cache"));
|
||||
process::exit(1);
|
||||
});
|
||||
|
|
|
|||
10
src/types.rs
10
src/types.rs
|
|
@ -185,16 +185,14 @@ impl LineType {
|
|||
}
|
||||
|
||||
/// The reason why a certain path (e.g. config path or cache dir) was chosen.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
pub enum PathSource {
|
||||
/// OS convention (e.g. XDG on Linux)
|
||||
OsConvention,
|
||||
/// Env variable (TEALDEER_*)
|
||||
EnvVar,
|
||||
|
||||
#[allow(dead_code)] // Waiting for Pull Request #141
|
||||
/// Config file variable
|
||||
ConfigVar,
|
||||
/// Config file
|
||||
ConfigFile,
|
||||
}
|
||||
|
||||
impl fmt::Display for PathSource {
|
||||
|
|
@ -205,7 +203,7 @@ impl fmt::Display for PathSource {
|
|||
match self {
|
||||
Self::OsConvention => "OS convention",
|
||||
Self::EnvVar => "env variable",
|
||||
Self::ConfigVar => "config file variable",
|
||||
Self::ConfigFile => "config file",
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue