diff options
| author | Weicao-CatilGrass <1992414357@qq.com> | 2026-04-27 11:31:59 +0800 |
|---|---|---|
| committer | Weicao-CatilGrass <1992414357@qq.com> | 2026-04-27 11:31:59 +0800 |
| commit | a3a657a4e0a4cc243846c6289a9d945e6eb35aa4 (patch) | |
| tree | 32f39f9caddbd2a75ef74e0ca52f7c75972b0482 /README.md | |
| parent | ae91bf2f6412edee65660085811248e0127fa97b (diff) | |
Update README with simple CLI example and restructure documentation
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 48 |
1 files changed, 47 insertions, 1 deletions
@@ -60,7 +60,53 @@ mingling = "0.1.7" mingling = { git = "https://github.com/catilgrass/mingling", branch = "main" } ``` -The following example demonstrates how to use `Mingling` to create a complete CLI program with `help`, `completion`, `fallback`, and `parsing`: +The example below shows how to use `Mingling` to create a simple CLI program: + +```rust +use mingling::macros::{dispatcher, gen_program, r_println, renderer}; + +fn main() { + let mut program = ThisProgram::new(); + program.with_dispatcher(HelloCommand); + + // Execute + program.exec(); +} + +// Define command: "<bin> hello" +dispatcher!("hello", HelloCommand => HelloEntry); + +// Render HelloEntry +#[renderer] +fn render_hello_world(_prev: HelloEntry) { + r_println!("Hello, World!") +} + +// Fallbacks +#[renderer] +fn fallback_dispatcher_not_found(prev: DispatcherNotFound) { + r_println!("Dispatcher not found for command `{}`", prev.join(", ")) +} + +#[renderer] +fn fallback_renderer_not_found(prev: RendererNotFound) { + r_println!("Renderer not found `{}`", *prev) +} + +// Collect renderers and chains to generate ThisProgram +gen_program!(); +``` + +Output: + +``` +> mycmd hello +Hello, World! +> mycmd hallo +Dispatcher not found for command `hallo` +``` + +Now, let's see the full usage of **Mingling**: The following example shows how to use `Mingling` to create a complete CLI program with `help`, `completion`, `fallback`, and `parser` features: ```rust use mingling::{ |
