Skip to main content

bctx_forge/awareness/
mod.rs

1pub mod build;
2pub mod git;
3pub mod lint;
4pub mod script;
5pub mod test;
6
7use std::collections::HashMap;
8
9/// Structured domain facts extracted from a RawSignal.
10#[derive(Debug, Clone, Default)]
11pub struct AwarenessMap {
12    pub ecosystem: String,
13    pub event_type: String,
14    pub facts: HashMap<String, String>,
15}
16
17impl AwarenessMap {
18    pub fn new(ecosystem: impl Into<String>, event_type: impl Into<String>) -> Self {
19        Self {
20            ecosystem: ecosystem.into(),
21            event_type: event_type.into(),
22            facts: HashMap::new(),
23        }
24    }
25
26    pub fn insert(&mut self, key: impl Into<String>, value: impl Into<String>) {
27        self.facts.insert(key.into(), value.into());
28    }
29
30    pub fn get(&self, key: &str) -> Option<&str> {
31        self.facts.get(key).map(|s| s.as_str())
32    }
33}
34
35pub trait EcosystemAwareness: Send + Sync {
36    fn matches(&self, program: &str, args: &[String]) -> bool;
37    fn extract(&self, stdout: &str, stderr: &str, exit_code: i32) -> AwarenessMap;
38}