diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/README.md | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/docs/README.md b/docs/README.md index 73fd091..6082508 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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::{ |
