SEN: CLI Engine
A type-safe, macro-powered CLI framework.
๐ฏ Philosophy
SEN transforms CLI development from ad-hoc scripts into systematic applications with:
- Compile-time safety: Enum-based routing with exhaustiveness checking
- Zero boilerplate: Derive macros generate all wiring code
- Type-driven DI: Handler parameters injected based on type signature
- Fixed workflows: Predictable behavior for humans and AI agents
- Strict separation: Prevents the "1000-line main.rs" problem
๐ Quick Start
Installation
Add to your Cargo.toml:
[]
= "0.1"
Or use cargo add:
Example (Router API - Recommended)
use ;
// 1. Define application state
// 2. Implement handlers as async functions
// 3. Wire it up with Router (< 20 lines of main.rs)
async
Example (Enum API - Type-safe alternative)
use ;
// 1. Define application state
// 2. Define commands with derive macro
// 3. Implement handlers as async functions
// 4. Wire it up (< 50 lines of main.rs)
async
That's it! The #[derive(SenRouter)] macro generates the execute() method that:
- Routes commands to handlers
- Injects
State<T>and args automatically - Converts results into responses with proper exit codes
๐ Project Structure
SEN enforces clean file separation from day one:
my-cli/
โโโ src/
โ โโโ main.rs # Entry point only (< 50 lines)
โ โโโ handlers/ # One file per command
โ โ โโโ mod.rs
โ โ โโโ status.rs
โ โ โโโ build.rs
โ โ โโโ test.rs
โ โโโ workflows/ # Multi-task operations
โ โ โโโ preflight.rs # fmt โ lint โ test
โ โโโ tasks/ # Atomic operations
โ โ โโโ fmt.rs
โ โ โโโ lint.rs
โ โโโ lib.rs # Re-exports
Why?
- Each command is independently testable
- No
println!debugging (handlers return structured data) - Impossible to create "1000-line main.rs"
- AI agents can understand and modify specific commands easily
๐จ Key Features
1. Flexible Routing - Choose Your Style
Router API (Axum-style) - Dynamic and flexible:
// Register handlers dynamically
let router = new
.route
.route
.with_state;
// Easy to integrate with existing CLIs
let response = router.execute.await;
Enum API - Compile-time safety:
Both approaches are supported - choose based on your needs:
- Router API: Better for gradual migration, dynamic routes, existing CLIs
- Enum API: Better for new projects, compile-time exhaustiveness checking
2. Axum-Style Handler Signatures
// Order doesn't matter!
pub async pub async
3. Smart Error Handling
Errors automatically format with helpful hints:
Error: Invalid argument '--foo'
The value 'bar' is not supported.
Hint: Use one of: baz, qux
4. No Println! in Handlers
Handlers return structured data, framework handles output:
// โ Bad: Can't test, can't redirect
pub async
// โ
Good: Testable, flexible
pub async
๐๏ธ Architecture
SEN follows a three-layer design:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Router Layer (Compile-time) โ
โ - Enum-based command tree โ
โ - Handler binding via proc macros โ
โ - Type-safe routing โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Handler Layer (Runtime) โ
โ - Dependency injection (State, Args) โ
โ - Business logic execution โ
โ - Result<T, E> return type โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Response Layer (Exit) โ
โ - Exit code mapping (0, 1, 101) โ
โ - Structured output (JSON/Human) โ
โ - Logging & telemetry โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
See DESIGN.md for full architecture details.
๐ Examples
Check out the examples/simple-cli directory for a working CLI with:
- Status command (no args)
- Build command (with
--releaseflag) - Test command (with optional filter)
- Proper error handling
Run it:
๐งช Testing
# Run all tests
# Test specific crate
๐ Documentation
- DESIGN.md - Complete design document
๐ฃ๏ธ Roadmap
- Phase 1: Core framework (State, CliResult, IntoResponse)
- Phase 2: Macro system (#[derive(SenRouter)])
- Phase 3: Advanced features (ReloadableConfig, tracing)
- Phase 4: Developer experience (CLI generator, templates)
๐ค Contributing
Contributions welcome! Please read DESIGN.md to understand the architecture first.
๐ License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
๐ Inspiration
SEN is inspired by:
- Axum - Type-safe handler functions
- Clap - CLI argument parsing
- The philosophy of Anti-Fragility and Fixed Workflows
SEN (็ท/ๅ ): The Line to Success, Leading the Future of CLI Development