Skip to main content

Crate lilyco

Crate lilyco 

Source
Expand description

§Lilyco — 门面(facade)

一个依赖搞定四端:CLI / TUI / Web / MCP(AI)

借鉴 mininterface 的接口工厂设计:按运行环境自动选择后端, 显式参数 > 环境变量 > 自动探测,TUI 起不来时回退 CLI。

§用法(零样板)

use lilyco::prelude::*;

#[derive(App)]
#[app(run = "run_hello")]
struct Hello {
    /// 问候对象
    name: String,
}

fn run_hello(app: &Hello, ctx: &Context) -> Result<serde_json::Value, AppError> {
    let r = serde_json::json!({ "msg": format!("hello {}", app.name) });
    ctx.done(r.clone(), 0);
    Ok(r)
}

fn main() {
    lilyco::run::<Hello>();
}

同一份二进制:

hello --name world        # CLI(非交互终端 / 管道)
hello                      # 交互终端 → TUI 表单
hello --gui                # Web GUI(SSE 进度)
hello --mcp                # MCP stdio 服务器(Agent 直接调用)
LILYCO_UI=web hello        # 环境变量强制后端

Modules§

prelude
常用导入(trait + 类型 + derive 宏)

Structs§

Env
环境快照(注入式,便于单元测试)

Enums§

Backend
可用的后端

Functions§

detect
真实环境下的探测(进程入口用)
detect_backend
自动探测后端。
run
一行启动:自动选择后端
run_cli_registry
以 CLI 多命令形态运行整个注册表(一个二进制 = 多个子命令)
run_tui_registry
以 TUI 多命令形态运行整个注册表(命令选择页 → 表单 → 执行)
run_with
显式指定后端
serve_mcp
以 MCP 服务器形态暴露整个注册表(多命令场景)