use crate::{
AuditState, Error, PrefixStore, ProbeStore, RewriteResult, audit_state,
domain::CommandRewriter, rewrite_command,
};
pub struct PrefixEngine<P: PrefixStore, Q: ProbeStore> {
prefix_store: P,
probe_store: Q,
}
impl<P: PrefixStore, Q: ProbeStore> PrefixEngine<P, Q> {
pub fn new(prefix_store: P, probe_store: Q) -> Self {
Self {
prefix_store,
probe_store,
}
}
pub fn rewrite(&self, cmd: &str) -> RewriteResult {
let config = self.prefix_store.load();
rewrite_command(cmd, &config)
}
pub fn audit(&self) -> AuditState {
audit_state(&self.prefix_store, &self.probe_store)
}
pub fn confirm(&self, key: &str, prefix: &[String]) -> Result<(), Error> {
self.prefix_store.confirm_mapping(key, prefix)
}
pub fn forget(&self, key: &str) -> Result<bool, Error> {
self.prefix_store.remove_mapping(key)
}
}
impl<P: PrefixStore, Q: ProbeStore> CommandRewriter for PrefixEngine<P, Q> {
fn rewrite(&self, cmd: &str) -> RewriteResult {
PrefixEngine::rewrite(self, cmd)
}
}