generated from GarandPLG/rust-flake-template
Simplify VeilFile loader API
This commit is contained in:
+1
-22
@@ -1,5 +1,3 @@
|
||||
use crate::config::VeilConfig;
|
||||
use anyhow::{Context, Result as AnyhowResult};
|
||||
use std::{
|
||||
fs::{File, create_dir_all, read_to_string},
|
||||
io::{Error, ErrorKind, Result, Write},
|
||||
@@ -9,22 +7,7 @@ use std::{
|
||||
pub struct VeilFile;
|
||||
|
||||
impl VeilFile {
|
||||
/// Load a config from an explicit `path`.
|
||||
pub fn load(path: &Path) -> AnyhowResult<VeilConfig> {
|
||||
let content: String = read_to_string(path)
|
||||
.with_context(|| format!("Cannot read config: {}", path.display()))?;
|
||||
|
||||
serde_yaml::from_str(&content).with_context(|| "Failed to parse veil.yaml")
|
||||
}
|
||||
|
||||
/// Find the default configuration file.
|
||||
///
|
||||
/// * If `debug` is true → tries `./local-config/veil.yaml`.
|
||||
/// * Otherwise → looks inside `$XDG_CONFIG_HOME/veil/` (or `$HOME/.config/veil/`).
|
||||
/// * The three accepted names are: `veil.yaml`, `.veil.yaml`, `veil.yml`.
|
||||
///
|
||||
/// Returns `Some(PathBuf)` when a file is found, otherwise `None`.
|
||||
pub fn find_default(debug: bool) -> Option<PathBuf> {
|
||||
pub fn load(debug: bool) -> Option<PathBuf> {
|
||||
if debug {
|
||||
let debug_path: &Path = Path::new("./local-config/veil.yaml");
|
||||
if debug_path.exists() {
|
||||
@@ -47,10 +30,6 @@ impl VeilFile {
|
||||
None
|
||||
}
|
||||
|
||||
/// Create a default configuration file based on the bundled example template.
|
||||
///
|
||||
/// * `debug` – if `true` we use the debug location (`./local-config/veil.yaml`);
|
||||
/// otherwise we use the XDG config directory (`$XDG_CONFIG_HOME/veil/veil.yaml`).
|
||||
pub fn init_config(debug: bool) -> Result<()> {
|
||||
let dest_dir: PathBuf = if debug {
|
||||
PathBuf::from("./local-config")
|
||||
|
||||
Reference in New Issue
Block a user