Macro magician in your CLI.
Warning
Note: Mingling is still under active development, and its API may change. Feel free to try it out and give us feedback!
Hint: This note will be removed in version 0.5.0
Mingling is a proc-macro and type system-based Rust CLI framework, suitable for developing complex command-line programs with numerous subcommands.
BTW: Its name comes from the Chinese Pinyin "Mìng Lìng", meaning "Command". 😄
- Separation of Concerns, Clear Logic: Mingling decouples logic by responsibility, helping you organize your CLI program more clearly. See example: Example
- "All Logic is Functions": Execution logic, rendering logic, completion logic, help logic — everything is a function. Just attach the corresponding attribute macro to bind them to your program.
- Fully Dynamic Completion System: With the
compfeature, you can flexibly implement dynamic completion logic for any subcommand. See examples: Example - Lightning-Fast Subcommand Dispatch: With the
dispatch_treefeature, Mingling hardens the subcommand structure into a prefix tree at compile time, enabling blazing-fast subcommand lookup. See examples: Example - Lightweight Dependencies, On-Demand Importing: Minimal core dependencies keep builds fast; enhanced features are imported on demand through fine-grained feature flags.
- Structured Output: Enabling the
general_rendererfeature adds support for flags like--jsonand--yaml, providing structured output capabilities. See examples: Example
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!(ResultGreeting = String);
#[chain]
fn handle_greet(args: EntryGreet) -> Next {
let greeting = args.pick_or::<String>((), "World").unpack();
ResultGreeting::new(greeting)
}
#[renderer]
fn render_greeting(greeting: ResultGreeting) {
r_println!("Hello, {}!", *greeting);
}
gen_program!();There are multiple ways to import Mingling:
- From crates.io:
[dependencies.mingling]
version = "0.1.9"
features = []- From GitHub:
[dependencies.mingling]
git = "https://github.com/catilgrass/mingling"
branch = "main"
features = []- Alternatively, you can quickly scaffold a new project from the Mingling-Template using:
cargo generate --git catilgrass/mingling-templateYou can read the following docs to learn more about the Mingling framework:
- 💡 Check out Mingling Helpdoc to learn the basics.
- 💡 Check out Examples to learn about the core library.
- 💡 Check out docs.rs to learn how to use the macro system and explore the full API.
-
Milestone.1 "MVP"
- [0.1.4] [
core] [general_renderer] Mingling can render data into serializable formats via--jsonand--yamlflags - [0.1.5] [
core] [comp] Mingling can dynamically invoke itself to provide completions for shells likebash,zsh,fish, andpwsh - [0.1.6] [
core] [comp] Mingling can gather more context for smarter completions - [0.1.7] [
clap] Provides a Clap compatibility layer, allowing Mingling to reuse its powerful parsing capabilities - [0.1.7] [
core] Mingling can intercept-hor--helpflags to display custom help text for each subcommand - [0.1.7] [
mling] Provides a basic scaffolding tool (mling) for rapid development and debugging - [0.1.8] [
core] [dispatch_tree] Converts the subcommand list into a prefix tree to improve command matching speed - [0.1.9] [
core] [dev_toolkits] Provides debugging interfaces for developers to capture invocation information when issues arise (InvokeStackDisplay) (indirectly implemented viaProgramHook) - [0.1.9] [
core] [repl] Provides REPL capability (program.exec_repl();) - [0.2.0] Complete documentation, tests, and examples
- [0.1.4] [
-
Milestone.2 "More Comfortable Dev and User Experience"
- ...
- [0.2.5] [
mling] Helpdoc Maker - ...
- [0.2.8] [
picker] A more efficient and intelligent argument parser
-
Milestone.3 "Unplanned"
- ...
While Mingling has several common CLI features that are NOT PLANNED to be directly included in the framework. This is because the Rust ecosystem already has excellent and mature crates to handle these issues, and Mingling's design is intended to be used in combination with them.
- Colored Output: To add color and styles (bold, italic, etc.) to terminal output, consider using crates like
coloredorowo-colors. You can integrate their types directly into your renderers. - I18n: To translate your CLI application, the
rust-i18ncrate provides a powerful internationalization solution that you can use in your command logic and renderers. - Progress Bars: To display progress indicators, the
indicatifcrate is the standard choice. - TUI: To build full-screen interactive terminal applications, it is recommended to use a framework like
ratatui(formerlytui-rs).
This project is licensed under the MIT License.
See LICENSE-MIT or LICENSE-APACHE file for details.