Expand description
Mingling
§Intro
Mingling is a Rust command-line framework. Its name comes from the Chinese Pinyin for “命令”, which means “Command”.
§Use
use mingling::macros::{dispatcher, gen_program, r_println, renderer};
#[tokio::main]
async fn main() {
let mut program = ThisProgram::new();
program.with_dispatcher(HelloCommand);
// Execute
program.exec().await;
}
// 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!();> mycmd hello
Hello, World!
> mycmd hallo
Dispatcher not found for command `hallo`§Features
compenables command completion functionality, see example for detailsparserenables themingling::parsermodule, see example for detailsgeneral_rendereradds support for serialized output formats such as JSON and YAML, see example for details
§Examples
Mingling provides detailed usage examples for your reference.
See Examples
Re-exports§
pub use mingling_core as mingling;
Modules§
- _mingling_
examples - Example projects for
Mingling, for learning how to useMingling - build
- Provides build scripts for users
- debug
- Provided for framework developers
- error
- All error types of
Mingling - macros
- Re-export from
mingling_macros - marker
- All marker types of
Minglingthat serve no practical purpose - setup
Mingling’s Program initialization system
Macros§
Structs§
- AnyOutput
- Any type output
- Dispatchers
- A collection of dispatchers.
- Flag
- A wrapper for a collection of static string slices representing command-line flags or arguments.
- Node
- Represents a command node, used to match user-input command paths.
- Program
- Program, used to define the behavior of the entire command-line program
- Program
Stdout Setting - Program stdout settings
- Program
User Context - Program user context
- Render
Result - Render result, containing the rendered text content.
Enums§
- Chain
Process - Chain exec result type
- Next
- Indicates the next step after processing
Traits§
- Chain
- Takes over a type (G: Previous) and converts it to another AnyOutput
- Dispatcher
- Dispatches user input commands to specific ChainProcess
- Groupped
- Used to mark a type with a unique enum ID, assisting dynamic dispatch
- Program
Collect - Collected program context
- Renderer
- Takes over a type (Self::Previous) and converts it to a
RenderResult
Functions§
Derive Macros§
- Groupped
- derive macro Groupped