[!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
π Contents
- π Intro
- β‘ Quick Start
- π§ Core Concepts
- ποΈ Project Structure
- π‘ Example Projects
- π£ Next Steps
- πΊοΈ Roadmap
- π« Unplanned Features
- π License
π Intro
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". π
β‘ Quick Start
To use a release version of
Mingling, get the latest version fromcrates.ioTo use the latest version, pull the project from the
mainbranch ongithub
If you have cargo-generate installed, you can quickly generate a new project template:
Otherwise, add Mingling to your Cargo.toml:
# From crates.io
= "0.1.8"
# From GitHub
= { = "https://github.com/catilgrass/mingling", = "main" }
The example below shows how to use Mingling to create a simple CLI program:
use ;
// Define command: "<bin> hello"
dispatcher!;
// Render HelloEntry
// Fallbacks
// Collect renderers and chains to generate ThisProgram
gen_program!;
Output:
> mycmd hello
Hello, World!
> mycmd hallo
Dispatcher not found for command `hallo`
Now, let's see the full usage of Mingling: The following example shows how to use Mingling to create a complete CLI program with help, completion, fallback, and parser features:
use ;
// Define dispatcher `greet`
dispatcher!;
// Define intermediate type `StateGreeting`
pack!;
// Define `greet` command help
// Define `greet` command completion
// Define chain, parsing `GreetEntry` into `StateGreeting`
// Render `StateGreeting`
// Define fallback logic when no matching dispatcher is found
// Generate program
gen_program!;
Output:
~> mycmd greet
Hello, World!
~> mycmd greet Alice
Hello, Alice!
~> mycmd greet --help
Usage: greet <NAME>
~> mycmd great
Command "great" not found.
π§ Core Concepts
Mingling abstracts command execution into the following parts:
- Dispatcher - Routes user input to a specific renderer or chain based on the command node name.
- Chain - Transforms the incoming type into another type, passing it to the next chain or renderer.
- Renderer - Stops the chain and prints the currently processed type to the terminal.
- Program - Manages the lifecycle and configuration of the entire CLI application.
ποΈ Project Structure
The Mingling project consists of two main parts:
- mingling/ - The core runtime library, containing type definitions, error handling, and basic functionality.
- mingling_macros/ - The procedural macro library, providing declarative macros to simplify development.
π‘ Example Projects
examples/example-basic/- A simple "Hello, World!" example demonstrating the most basic usage of a Dispatcher and Renderer.examples/example-async/- Based onexample-basic, demonstrates how to integrate an async runtimeexamples/example-picker/- Demonstrates how to use a Chain to process and transform command arguments.examples/example-general-renderer/- Shows how to use a general renderer for different data types (e.g., JSON, YAML, TOML, RON).examples/example-completion/- An example implementing auto-completion for the shell.
π£ Next Steps
You can read the following docs to learn more about the Mingling framework:
- Check out Mingling Helpdoc to learn the basics.
- Check out Mingling Examples to learn about the core library.
- Check out Mingling Docs to learn how to use the macro system and explore the full API.
πΊοΈ Roadmap
-
Milestone.1
- [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) - [0.1.9] [
core] [repl] Provides REPL capability (program.exec_repl();)
- [0.1.4] [
-
Milestone.2
- ...
- [0.2.5] [
mling] Helpdoc Maker
π« Unplanned Features
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).
π License
This project is licensed under the MIT License.
See LICENSE-MIT or LICENSE-APACHE file for details.