1
0
Fork 0
mirror of https://codeberg.org/icewind/haze.git synced 2026-06-04 17:44:11 +02:00

edit command

This commit is contained in:
Robin Appelman 2025-09-03 18:37:33 +02:00
commit 43481a5960
5 changed files with 70 additions and 9 deletions

View file

@ -1,5 +1,5 @@
use crate::config::{HazeConfig, HazeVolumeConfig};
use camino::Utf8Path;
use camino::{Utf8Path, Utf8PathBuf};
use miette::{IntoDiagnostic, Result};
use tokio::fs::{create_dir_all, write};
@ -7,7 +7,7 @@ use tokio::fs::{create_dir_all, write};
pub struct Mapping<'a> {
source_type: MappingSourceType,
pub source: &'a Utf8Path,
target: &'a Utf8Path,
pub target: &'a Utf8Path,
mapping_type: MappingType,
read_only: bool,
map: bool,
@ -78,16 +78,20 @@ impl<'a> Mapping<'a> {
Ok(())
}
pub fn get_volume_arg(&self, id: &str, config: &HazeConfig) -> Option<String> {
if !self.map {
return None;
}
let source = match self.source_type {
pub fn source(&self, id: &str, config: &HazeConfig) -> Utf8PathBuf {
match self.source_type {
MappingSourceType::WorkDir => config.work_dir.join(id).join(self.source),
MappingSourceType::GlobalWorkDir => config.work_dir.join(self.source),
MappingSourceType::Sources => config.sources_root.join(self.source),
MappingSourceType::Absolute => self.source.into(),
};
}
}
pub fn get_volume_arg(&self, id: &str, config: &HazeConfig) -> Option<String> {
if !self.map {
return None;
}
let source = self.source(id, config);
Some(if self.read_only {
format!("{}:{}:ro", source, self.target)
} else {