Skip to main content

Crate mingling

Crate mingling 

Source
Expand description

Mingling

§Intro

A Rust CLI framework for many subcmds & complex workflows, reduces boilerplate via proc macros, focus on biz logic

§Use

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!();
> mycmd hello
Hello, World!
> mycmd hallo
Dispatcher not found for command `hallo`

§Features

  • async enables async runtime support for command execution, see example for details
  • 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
feature
Module for checking which features are enabled at compile time.
macros
Re-export from mingling_macros
parser
Mingling argument parser
prelude
The prelude module provides convenient re-exports of commonly used macros and traits.
res
Mutable global resources provided within Mingling
setup
Setups provided by Mingling, which can extend command-line programs.
test
Provides a toolkit for Mingling testing capabilities.

Macros§

assert_chain_result
Asserts that a chain process result is Ok and has the expected output type.
assert_member_id
Asserts that the result’s output type matches the expected member_id.
assert_next
Asserts that a chain process result has the expected output type and next state.
assert_render_result
Alias for assert_chain_result.
debug
Logs a message at the debug level, but only if the debug feature is enabled. Delegates to log::debug! internally.
error
Logs a message at the error level, but only if the debug feature is enabled. Delegates to log::error! internally.
info
Logs a message at the info level, but only if the debug feature is enabled. Delegates to log::info! internally.
only_debug
A macro that only executes the given expressions when the debug feature is enabled. If the feature is not enabled, the expressions are compiled away.
trace
Logs a message at the trace level, but only if the debug feature is enabled. Delegates to log::trace! internally.
warn
Logs a message at the warn level, but only if the debug feature is enabled. Delegates to log::warn! internally.

Structs§

AnyOutput
Any type output
CompletionHelper
A helper struct for handling command-line completion logic.
Dispatchers
A collection of dispatchers.
Flag
A wrapper for a collection of static string slices representing command-line flags or arguments.
GeneralRenderer
A general renderer that supports multiple serialization formats.
GlobalResource
Global assets for storing Program global state information
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.
ShellContext
Context passed from the shell to the completion system, providing information about the current command line state to guide how completions should be generated.

Enums§

ChainProcess
Chain exec result type
GeneralRendererSetting
Settings for the general renderer output format.
NextProcess
Indicates the next step after processing
ShellFlag
Represents the shell environment for which the output format is intended.
Suggest
A completion suggestion that tells the shell how to perform completion. This can be either a set of specific suggestion items or a request for file completion.
SuggestItem
Represents a single suggestion item for shell completion.

Traits§

Chain
Takes over a type (G: Previous) and converts it to another AnyOutput
Completion
Trait for implementing completion logic.
CompletionEntry
Trait for extracting user input arguments for completion.
Dispatcher
Dispatches user input commands to specific ChainProcess
EnumTag
Marker trait for EnumTag
Groupped
Used to mark a type with a unique enum ID, assisting dynamic dispatch
HelpRequest
Handles help rendering for command-line arguments
ProgramCollect
Collected program context
Renderer
Takes over a type (Self::Previous) and converts it to a RenderResult
ResourceMarker
Resource marker trait, types that implement the Clone and Default traits can be considered as resources

Functions§

get_nodes
Get all registered dispatcher names from the program
this
Returns a reference to the current program instance, panics if not set.

Derive Macros§

EnumTag
derive macro EnumTag Derive macro for automatically implementing the EnumTag trait on an enum with unit-only variants.
Groupped
derive macro Groupped Derive macro for automatically implementing the Groupped trait on a struct.