1
0
Fork 0
mirror of https://codeberg.org/icewind/haze.git synced 2026-06-03 17:14:08 +02:00

allow sources/workdir paths starting with ~

This commit is contained in:
Robin Appelman 2022-08-05 13:26:39 +02:00
commit b86d2f890d

View file

@ -3,10 +3,21 @@ use directories_next::ProjectDirs;
use miette::{IntoDiagnostic, Report, Result, WrapErr};
use serde::Deserialize;
use std::convert::TryFrom;
use std::env::var;
use std::fs::{read, read_to_string};
#[derive(Debug, Deserialize)]
#[serde(from = "RawHazeConfig")]
pub struct HazeConfig {
pub sources_root: Utf8PathBuf,
pub work_dir: Utf8PathBuf,
pub auto_setup: HazeAutoSetupConfig,
pub volume: Vec<HazeVolumeConfig>,
pub blackfire: Option<HazeBlackfireConfig>,
}
#[derive(Debug, Deserialize)]
pub struct RawHazeConfig {
pub sources_root: Utf8PathBuf,
#[serde(default = "default_work_dir")]
pub work_dir: Utf8PathBuf,
@ -18,6 +29,27 @@ pub struct HazeConfig {
pub blackfire: Option<HazeBlackfireConfig>,
}
impl From<RawHazeConfig> for HazeConfig {
fn from(raw: RawHazeConfig) -> Self {
fn normalize_path(path: Utf8PathBuf) -> Utf8PathBuf {
if path.starts_with("~") {
let home = var("HOME").expect("HOME not set");
format!("{}{}", home, &path.as_str()[1..]).into()
} else {
path
}
}
HazeConfig {
sources_root: normalize_path(raw.sources_root),
work_dir: normalize_path(raw.work_dir),
auto_setup: raw.auto_setup,
volume: raw.volume,
blackfire: raw.blackfire,
}
}
}
#[derive(Debug, Deserialize)]
pub struct HazeAutoSetupConfig {
pub enabled: bool,