pub mod executor;
pub mod parser;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DslRequest {
pub dsl: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DslLine {
pub text: String,
pub cls: String,
}
impl DslLine {
pub fn success(text: impl Into<String>) -> Self {
Self {
text: text.into(),
cls: "cli-success".to_string(),
}
}
pub fn muted(text: impl Into<String>) -> Self {
Self {
text: text.into(),
cls: "cli-muted".to_string(),
}
}
pub fn error(text: impl Into<String>) -> Self {
Self {
text: text.into(),
cls: "cli-error".to_string(),
}
}
pub fn info(text: impl Into<String>) -> Self {
Self {
text: text.into(),
cls: "cli-info".to_string(),
}
}
pub fn blank() -> Self {
Self {
text: String::new(),
cls: "cli-blank".to_string(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct DslOutput {
pub ok: bool,
pub lines: Vec<DslLine>,
}
impl DslOutput {
pub fn new_ok() -> Self {
Self {
ok: true,
lines: Vec::new(),
}
}
pub fn new_err(msg: impl Into<String>) -> Self {
Self {
ok: false,
lines: vec![DslLine::error(msg)],
}
}
pub fn push(&mut self, line: DslLine) {
self.lines.push(line);
}
pub fn extend(&mut self, lines: impl IntoIterator<Item = DslLine>) {
self.lines.extend(lines);
}
pub fn err(msg: impl Into<String>) -> Self {
Self::new_err(msg)
}
}