Skip to main content

Crate mingling

Crate mingling 

Source
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

  • comp enables command completion functionality, see example for details
  • parser enables the mingling::parser module, see example for details
  • general_renderer adds 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 use Mingling
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 Mingling that serve no practical purpose
setup
Mingling’s Program initialization system

Macros§

debug
error
info
only_debug
trace
warn

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
ProgramStdoutSetting
Program stdout settings
ProgramUserContext
Program user context
RenderResult
Render result, containing the rendered text content.

Enums§

ChainProcess
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
ProgramCollect
Collected program context
Renderer
Takes over a type (Self::Previous) and converts it to a RenderResult

Functions§

get_nodes
this
Returns a reference to the current program instance, panics if not set.

Derive Macros§

Groupped
derive macro Groupped