specfold_core/check/
context.rs1use super::scope::Scope;
4use crate::corpus::Corpus;
5use crate::graph::Graph;
6use crate::workspace::vcs;
7
8#[derive(Debug, Clone, Default)]
9pub struct Options {
10 pub run_commands: bool,
12 pub external: bool,
14 pub online: bool,
16}
17
18pub struct Ctx<'a> {
19 pub corpus: &'a Corpus,
20 pub graph: &'a Graph,
21 pub scope: &'a Scope,
22 pub opts: &'a Options,
23}
24
25impl Ctx<'_> {
26 pub fn previous(&self, path: &str) -> Option<String> {
28 let base = self.scope.base.as_deref()?;
29 vcs::show(&self.corpus.cfg.root, base, path)
30 }
31
32 pub fn current(&self, path: &str) -> Option<String> {
34 match self.scope.range {
35 super::scope::Range::Staged => vcs::show_staged(&self.corpus.cfg.root, path),
36 _ => std::fs::read_to_string(self.corpus.cfg.root.join(path)).ok(),
37 }
38 }
39}