Remove repo content parsing to submodule

main
trivernis 9 months ago
parent e1718162ee
commit efd1d54c2c
Signed by: Trivernis
GPG Key ID: 7E6D18B61C8D2F4B

@ -1,70 +1,38 @@
use chksum::sha2_256::chksum;
use dialoguer::Confirm;
use globset::{Glob, GlobSet, GlobSetBuilder};
use miette::{bail, Context, IntoDiagnostic, Result};
use serde::{Deserialize, Serialize};
use std::{
env,
fs::{self, File},
io::Write,
path::{Path, PathBuf},
process::Command,
rc::Rc,
};
use tempfile::NamedTempFile;
use crate::{
config::{read_config, SiloConfig},
templating,
};
use crate::templating;
use super::{ApplyContext, ParseContext};
use chksum::sha2_256::chksum;
use dialoguer::Confirm;
use globset::{Glob, GlobSet, GlobSetBuilder};
use lazy_static::lazy_static;
use miette::{Context, IntoDiagnostic, Result};
use serde::{Deserialize, Serialize};
use tempfile::NamedTempFile;
#[derive(Clone, Debug)]
pub struct SiloRepo {
pub struct Contents {
pub root: DirEntry,
pub config: SiloConfig,
}
impl SiloRepo {
pub fn open(path: &Path) -> Result<Self> {
if !path.try_exists().into_diagnostic()? {
bail!("The repository {path:?} does not exist");
}
let config = read_config(path)?;
Ok(Self {
root: DirEntry::parse(
Rc::new(ParseContext::new(GlobSet::empty(), config.clone())),
path.to_owned(),
)?,
config,
})
}
pub fn apply(&self) -> Result<()> {
let cwd = dirs::home_dir().unwrap_or(env::current_dir().into_diagnostic()?);
let ctx = ApplyContext {
config: self.config.clone(),
};
self.root.apply(&ctx, &cwd)
impl Contents {
pub fn parse(pctx: ParseContext, path: PathBuf) -> Result<Self> {
let root = DirEntry::parse(Rc::new(pctx), path.to_owned())?;
Ok(Self { root })
}
}
pub struct ParseContext {
ignored: GlobSet,
config: SiloConfig,
}
impl ParseContext {
pub fn new(ignored: GlobSet, config: SiloConfig) -> Self {
Self { ignored, config }
pub fn apply(&self, actx: &ApplyContext, cwd: &Path) -> Result<()> {
self.root.apply(actx, cwd)
}
}
pub struct ApplyContext {
config: SiloConfig,
}
lazy_static! {
static ref IGNORED_PATHS: GlobSet = GlobSetBuilder::new()
.add(Glob::new("**/.git").unwrap())

@ -0,0 +1,54 @@
mod contents;
use globset::GlobSet;
use miette::{bail, IntoDiagnostic, Result};
use std::{env, path::Path};
use crate::config::{read_config, SiloConfig};
use self::contents::Contents;
#[derive(Clone, Debug)]
pub struct SiloRepo {
pub config: SiloConfig,
contents: Contents,
}
impl SiloRepo {
pub fn open(path: &Path) -> Result<Self> {
if !path.try_exists().into_diagnostic()? {
bail!("The repository {path:?} does not exist");
}
let config = read_config(path)?;
let pctx = ParseContext::new(GlobSet::empty(), config.clone());
Ok(Self {
contents: Contents::parse(pctx, path.to_owned())?,
config,
})
}
pub fn apply(&self) -> Result<()> {
let cwd = dirs::home_dir().unwrap_or(env::current_dir().into_diagnostic()?);
let ctx = ApplyContext {
config: self.config.clone(),
};
self.contents.apply(&ctx, &cwd)
}
}
pub struct ParseContext {
ignored: GlobSet,
config: SiloConfig,
}
impl ParseContext {
pub fn new(ignored: GlobSet, config: SiloConfig) -> Self {
Self { ignored, config }
}
}
pub struct ApplyContext {
config: SiloConfig,
}
Loading…
Cancel
Save