name: add-plugin description: Add a new plugin binary to thin-edge.io. Use when creating a new extension of built-in operations supported by tedge-agent.
Add Plugin Binary
Steps
- Create crate directory
plugins/<name>/with asrc/lib.rsandsrc/bin.rs(and optionallysrc/main.rs). Themain.rsfile is used only for integration testing. The real plugin invocation happens via thetedgemulti-call binary. - Generate
Cargo.tomlwith workspace conventions:[package] name = "<name>" version.workspace = true edition.workspace = true license.workspace = true [lints] workspace = true [dependencies] clap = { workspace = true } # add other workspace deps as needed - Add to workspace members in root
Cargo.toml— plugins are listed explicitly (not globbed):members = [ # ...existing... "plugins/<name>", ] - Define CLI with
#[derive(clap::Parser)]and aPluginOpsubcommand enum:#[derive(clap::Subcommand)] pub enum PluginOp { Subcommand1, Subcommand2 # ...remaining supported subcommands } - Implement
run()in thebin.rsthat handles each subcommand variant and returns ananyhow::Result<()>. - Add this library as a dependency of the
crates/core/tedgemulti-call binary crate. - Call this
run()from the multi-call binary definition atcrates/core/tedge/src/main.rs. - Verify: Run
just checkandjust test
Reference Files
Read these for patterns:
plugins/tedge_apt_plugin/src/lib.rs— library-only pattern with clap CLI andrun_and_exit()plugins/tedge_file_log_plugin/src/main.rs— bin.rs + lib.rs pattern