Expand description
Mingling
§Intro
Mingling is a proc-macro and type system-based Rust CLI framework, suitable for developing complex command-line programs with numerous subcommands.
§Use
Here is a basic project written using Mingling:
- When the user types
greet, the program outputsHello, World! - When the user types
greet Alice, the program outputsHello, Alice!
use mingling::prelude::*;
dispatcher!("greet", CMDGreet => EntryGreet);
fn main() {
let mut program = ThisProgram::new();
program.with_dispatcher(CMDGreet);
program.exec_and_exit();
}
pack!(ResultName = String);
#[chain]
fn handle_greet(args: EntryGreet) -> Next {
let name: ResultName = args
.inner
.first()
.cloned()
.unwrap_or_else(|| "World".to_string())
.into();
name
}
#[renderer]
fn render_name(name: ResultName) {
r_println!("Hello, {}!", *name);
}
#[renderer]
fn render_dispatcher_not_found(err: ErrorDispatcherNotFound) {
if err.len() > 0 {
r_println!("Command not found: [{}]", err.join(" "));
}
}
gen_program!();> mycmd greet
Hello, World!
> mycmd greet Alice
Hello, Alice!
> mycmd great
Command not found: [great]§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
- REPL
- Internal resource for the REPL runtime, used to control the REPL’s state during execution
- 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.