Skip to main content

invoice_cli/
config.rs

1// ═══════════════════════════════════════════════════════════════════════════
2// Thin shim over finance-core — preserves the invoice-cli call-site API
3// (`config::load`, `config::config_path`, `config::db_path`, etc.) so the
4// rest of the crate doesn't have to learn finance-core's module layout.
5//
6// Real storage and path resolution live in finance-core:
7//   - Settings struct       → finance_core::settings::Settings (aliased here)
8//   - Shared config.toml    → finance_core::paths::Paths::config_file()
9//   - Shared SQLite db      → finance_core::paths::Paths::db_file()
10//   - Asset root (Typst)    → finance_core::paths::Paths::assets_dir()
11// ═══════════════════════════════════════════════════════════════════════════
12
13use std::path::PathBuf;
14
15use finance_core::paths::Paths;
16pub use finance_core::settings::Settings as Config;
17
18use crate::error::Result;
19
20fn paths() -> Result<Paths> {
21    Ok(Paths::resolve()?)
22}
23
24pub fn config_path() -> Result<PathBuf> {
25    Ok(paths()?.config_file())
26}
27
28pub fn state_path() -> Result<PathBuf> {
29    Ok(paths()?.data_dir)
30}
31
32pub fn db_path() -> Result<PathBuf> {
33    Ok(paths()?.db_file())
34}
35
36pub fn assets_path() -> Result<PathBuf> {
37    Ok(paths()?.assets_dir())
38}
39
40pub fn load() -> Result<Config> {
41    let p = paths()?;
42    Ok(Config::load(&p)?)
43}
44
45pub fn ensure_dirs() -> Result<()> {
46    let p = paths()?;
47    std::fs::create_dir_all(p.assets_dir())?;
48    Ok(())
49}