Skip to content

Commit bd98428

Browse files
committed
feat(plugin-tee): setup
1 parent 6276ec1 commit bd98428

File tree

6 files changed

+83
-0
lines changed

6 files changed

+83
-0
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ members = [
77
"crates/plugin-ls",
88
"crates/plugin-cat",
99
"crates/plugin-weather",
10+
"crates/plugin-tee",
1011
"crates/repl-logic-guest",
1112
]
1213

crates/plugin-tee/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/bindings.rs

crates/plugin-tee/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "plugin-tee"
3+
version = "0.1.0"
4+
edition = { workspace = true }
5+
publish = false
6+
description = "Example tee plugin for REPL based on WebAssembly Component Model - demonstrates file system access and modification"
7+
8+
[dependencies]
9+
wit-bindgen-rt = { workspace = true, features = ["bitflags"] }
10+
11+
[lib]
12+
crate-type = ["cdylib"]
13+
14+
[package.metadata.component]
15+
package = "repl:api"
16+
target = { path = "../pluginlab/wit", world = "plugin-api" }
17+
18+
[package.metadata.component.dependencies]

crates/plugin-tee/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# plugin-tee
2+
3+
Basic plugin for this REPL. Behaves like the `tee` command.
4+
5+
## Notes
6+
7+
This crate was initialized with `cargo component new`.
8+
9+
The building process is handled by the [`justfile`](../../justfile) in the root of the project.
10+
11+
The `cargo component build` command is used to build the plugin.
12+
13+
- It generates the `src/bindings.rs` file, based on the `package.metadata.component` section in the `Cargo.toml` file that describes where to find the component definition (wit files).
14+
- It then compiles the plugin to WebAssembly.

crates/plugin-tee/src/lib.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#[allow(warnings)]
2+
mod bindings;
3+
4+
use crate::bindings::exports::repl::api::plugin::Guest;
5+
use crate::bindings::repl::api::transport;
6+
7+
struct Component;
8+
9+
impl Guest for Component {
10+
fn name() -> String {
11+
"tee".to_string()
12+
}
13+
14+
fn man() -> String {
15+
r#"
16+
NAME
17+
tee - Copy $0 content to a file (built with Rust🦀)
18+
19+
USAGE
20+
tee <file>
21+
tee -a <file>
22+
23+
OPTIONS
24+
-a, --append Append to the file instead of overwriting it
25+
26+
DESCRIPTION
27+
Copy $0 content to a file.
28+
29+
"#
30+
.to_string()
31+
}
32+
33+
fn run(payload: String) -> Result<transport::PluginResponse, ()> {
34+
Ok(transport::PluginResponse {
35+
status: transport::ReplStatus::Success,
36+
stdout: Some(format!("{}", payload)),
37+
stderr: None,
38+
})
39+
}
40+
}
41+
42+
bindings::export!(Component with_types_in bindings);

0 commit comments

Comments
 (0)