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
asyncenables async runtime support for command execution, see example for detailscompenables 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 - feature
- Module for checking which features are enabled at compile time.
- macros
- Re-export from
mingling_macros - parser
Minglingargument 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
Minglingtesting 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
debugfeature is enabled. Delegates tolog::debug!internally. - error
- Logs a message at the error level, but only if the
debugfeature is enabled. Delegates tolog::error!internally. - info
- Logs a message at the info level, but only if the
debugfeature is enabled. Delegates tolog::info!internally. - only_
debug - A macro that only executes the given expressions when the
debugfeature 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
debugfeature is enabled. Delegates tolog::trace!internally. - warn
- Logs a message at the warn level, but only if the
debugfeature is enabled. Delegates tolog::warn!internally.
Structs§
- AnyOutput
- Any type output
- Completion
Helper - 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.
- General
Renderer - A general renderer that supports multiple serialization formats.
- Global
Resource - 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
- Program
Stdout Setting - Program stdout settings
- Program
User Context - Program user context
- Render
Result - Render result, containing the rendered text content.
- Shell
Context - 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§
- Chain
Process - Chain exec result type
- General
Renderer Setting - Settings for the general renderer output format.
- Next
Process - Indicates the next step after processing
- Shell
Flag - 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.
- Suggest
Item - 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.
- Completion
Entry - 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
- Help
Request - Handles help rendering for command-line arguments
- Program
Collect - Collected program context
- Renderer
- Takes over a type (Self::Previous) and converts it to a
RenderResult - Resource
Marker - 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.