mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 09:04:12 +02:00
edit command
This commit is contained in:
parent
7a96e6cd71
commit
43481a5960
5 changed files with 70 additions and 9 deletions
25
src/cloud.rs
25
src/cloud.rs
|
|
@ -15,6 +15,7 @@ use futures_util::future::try_join_all;
|
|||
use miette::{IntoDiagnostic, Report, Result, WrapErr};
|
||||
use petname::petname;
|
||||
use serde_json::Value;
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::Display;
|
||||
use std::fs;
|
||||
|
|
@ -767,4 +768,28 @@ impl Cloud {
|
|||
pub fn php(&self) -> &PhpVersion {
|
||||
&self.options.php
|
||||
}
|
||||
|
||||
pub fn get_local_path(&self, config: &HazeConfig, path: &str) -> Option<Utf8PathBuf> {
|
||||
let path = if path.starts_with('/') {
|
||||
Cow::Borrowed(path)
|
||||
} else {
|
||||
format!("/var/www/html/{path}").into()
|
||||
};
|
||||
|
||||
let mut mappings = config
|
||||
.volume
|
||||
.iter()
|
||||
.map(Mapping::from)
|
||||
.chain(default_mappings())
|
||||
.collect::<Vec<_>>();
|
||||
mappings.sort_by_key(|mapping| usize::MAX - mapping.target.as_str().len());
|
||||
|
||||
for mapping in mappings {
|
||||
if let Some(rel_path) = path.strip_prefix(mapping.target.as_str()) {
|
||||
let rel_path = rel_path.trim_matches('/');
|
||||
return Some(mapping.source(&self.id, config).join(rel_path));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue