use crate::{
error::Error,
types::{config::Config, Value},
utils as client_utils,
};
use futures::Stream;
use std::fmt;
mod parser;
mod utils;
#[derive(Clone, Debug)]
pub struct MonitorCommand {
pub command: String,
pub args: Vec<Value>,
pub timestamp: f64,
pub db: u8,
pub client: String,
}
impl PartialEq for MonitorCommand {
fn eq(&self, other: &Self) -> bool {
client_utils::f64_eq(self.timestamp, other.timestamp)
&& self.client == other.client
&& self.db == other.db
&& self.command == other.command
&& self.args == other.args
}
}
impl Eq for MonitorCommand {}
impl fmt::Display for MonitorCommand {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{:.6} [{} {}] \"{}\"",
self.timestamp, self.db, self.client, self.command
)?;
for arg in self.args.iter() {
write!(f, " \"{}\"", arg.as_str().unwrap_or("unknown".into()))?;
}
Ok(())
}
}
pub async fn run(config: Config) -> Result<impl Stream<Item = MonitorCommand>, Error> {
utils::start(config).await
}