btctax_cli/price_cache.rs
1//! Resolve the local price-cache path (#41 Part C). `dirs` lives HERE (and in `btctax-update-prices`),
2//! NOT in btctax-adapters [R0-M2/r2 M-A] — the adapter's `LayeredPrices` takes an ALREADY-resolved
3//! `cache_path` and stays a pure format/provider crate (no `dirs`, no network). The cache is a documented
4//! LOCAL INPUT the offline projection layers OVER the bundled dataset; it is populated ONLY by the
5//! separate `btctax-update-prices` binary, so btctax-cli itself carries NO network dependency.
6use std::path::PathBuf;
7
8/// The env var that overrides the default cache location (tests / reproducibility / custom data dirs).
9pub const PRICE_CACHE_ENV: &str = "BTCTAX_PRICE_CACHE";
10
11/// The pointer surfaced next to a "no price for {date}" condition — a STRING only (no dep, no shell-out):
12/// the tax binaries never fetch; the user runs the separate updater explicitly.
13pub const UPDATE_PRICES_HINT: &str =
14 "no local price for this date — run `btctax-update-prices` to fetch newer daily closes into the cache";
15
16/// The default local price-cache path: `$BTCTAX_PRICE_CACHE` if set, else
17/// `<data_dir>/btctax/price_cache.csv` (`dirs::data_dir()`), else `None` (no platform data dir ⇒
18/// bundled-only — still fully functional, just no cache overlay).
19pub fn default_cache_path() -> Option<PathBuf> {
20 if let Some(p) = std::env::var_os(PRICE_CACHE_ENV) {
21 return Some(PathBuf::from(p));
22 }
23 dirs::data_dir().map(|d| d.join("btctax").join("price_cache.csv"))
24}