refactor: fully complete state re-architecting
This commit is contained in:
+12
-4
@@ -1,12 +1,12 @@
|
||||
use crate::config::paths;
|
||||
use crate::config::{Config, RequestContext, RoleLike, ensure_parent_exists};
|
||||
use crate::config::{RequestContext, RoleLike, ensure_parent_exists};
|
||||
use crate::repl::{run_repl_command, split_args_text};
|
||||
use crate::utils::{AbortSignal, multiline_text};
|
||||
use anyhow::{Result, anyhow};
|
||||
use anyhow::{Context, Result, anyhow};
|
||||
use indexmap::IndexMap;
|
||||
use rust_embed::Embed;
|
||||
use serde::Deserialize;
|
||||
use std::fs::File;
|
||||
use std::fs::{File, read_to_string};
|
||||
use std::io::Write;
|
||||
|
||||
#[derive(Embed)]
|
||||
@@ -20,7 +20,7 @@ pub async fn macro_execute(
|
||||
args: Option<&str>,
|
||||
abort_signal: AbortSignal,
|
||||
) -> Result<()> {
|
||||
let macro_value = Config::load_macro(name)?;
|
||||
let macro_value = Macro::load(name)?;
|
||||
let (mut new_args, text) = split_args_text(args.unwrap_or_default(), cfg!(windows));
|
||||
if !text.is_empty() {
|
||||
new_args.push(text.to_string());
|
||||
@@ -76,6 +76,14 @@ pub struct Macro {
|
||||
}
|
||||
|
||||
impl Macro {
|
||||
pub fn load(name: &str) -> Result<Macro> {
|
||||
let path = paths::macro_file(name);
|
||||
let err = || format!("Failed to load macro '{name}' at '{}'", path.display());
|
||||
let content = read_to_string(&path).with_context(err)?;
|
||||
let value: Macro = serde_yaml::from_str(&content).with_context(err)?;
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
pub fn install_macros() -> Result<()> {
|
||||
info!(
|
||||
"Installing built-in macros in {}",
|
||||
|
||||
Reference in New Issue
Block a user