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:
parent
1b03d7899e
commit
b86d2f890d
1 changed files with 32 additions and 0 deletions
|
|
@ -3,10 +3,21 @@ use directories_next::ProjectDirs;
|
||||||
use miette::{IntoDiagnostic, Report, Result, WrapErr};
|
use miette::{IntoDiagnostic, Report, Result, WrapErr};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
use std::env::var;
|
||||||
use std::fs::{read, read_to_string};
|
use std::fs::{read, read_to_string};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[serde(from = "RawHazeConfig")]
|
||||||
pub struct HazeConfig {
|
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,
|
pub sources_root: Utf8PathBuf,
|
||||||
#[serde(default = "default_work_dir")]
|
#[serde(default = "default_work_dir")]
|
||||||
pub work_dir: Utf8PathBuf,
|
pub work_dir: Utf8PathBuf,
|
||||||
|
|
@ -18,6 +29,27 @@ pub struct HazeConfig {
|
||||||
pub blackfire: Option<HazeBlackfireConfig>,
|
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)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct HazeAutoSetupConfig {
|
pub struct HazeAutoSetupConfig {
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue