Skip to content

Commit

Permalink
add: text hook
Browse files Browse the repository at this point in the history
  • Loading branch information
momeemt committed Oct 18, 2024
1 parent ffc4bd8 commit 3320008
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ use brack_pdk_rs::metadata::Metadata;
use document::metadata_document;
use extism_pdk::{plugin_fn, FnResult, Json};
use stmt::metadata_stmt;
use text::metadata_text;

pub mod document;
pub mod bold;
pub mod stmt;
pub mod text;

#[plugin_fn]
pub fn get_metadata() -> FnResult<Json<Vec<Metadata>>> {
let mut metadata = Vec::new();
metadata.push(metadata_bold());
metadata.push(metadata_document());
metadata.push(metadata_stmt());
metadata.push(metadata_text());
Ok(Json(metadata))
}
28 changes: 28 additions & 0 deletions src/text.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use brack_pdk_rs::{metadata::Metadata, types::Type, values::Value};
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};

pub(crate) fn metadata_text() -> Metadata {
Metadata {
command_name: "text".to_string(),
call_name: "text".to_string(),
argument_types: vec![("text".to_string(), Type::TInline)],
return_type: Type::TInline,
}
}

#[plugin_fn]
pub fn text(Json(args): Json<Vec<Value>>) -> FnResult<String> {
if args.len() != 1 {
return Err(WithReturnCode::new(anyhow::anyhow!("text failed"), 1));
}
let text = match &args[0] {
Value::Text(t) => t,
_ => {
return Err(WithReturnCode::new(
anyhow::anyhow!("text must be Value::Text"),
1,
))
}
};
Ok(format!("{{\"t\": \"Str\", \"c\": \"{}\"}}", text))
}

0 comments on commit 3320008

Please sign in to comment.