diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-04-14 22:47:08 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-04-14 22:47:08 +0800 |
| commit | b9edeb9848e4a423e133fa2a13dede6d128d6f08 (patch) | |
| tree | f8f9e03bf3e64b98f3e5de57fd5d0686bf4739b2 /docs/pages/1-get-started.md | |
| parent | de54d14f315c96a1003b8956086828fc75ddf49d (diff) | |
Add documentation for Mingling CLI framework
Diffstat (limited to 'docs/pages/1-get-started.md')
| -rw-r--r-- | docs/pages/1-get-started.md | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/docs/pages/1-get-started.md b/docs/pages/1-get-started.md new file mode 100644 index 0000000..f4edfc0 --- /dev/null +++ b/docs/pages/1-get-started.md @@ -0,0 +1,69 @@ +# Get Started +This article explains how to quickly create your first **Mingling** command-line program. + +## Quick Start +1. Add `mingling` to your Rust project. +```bash +cargo add mingling +``` +Or add the following to your `Cargo.toml`: +```toml +[dependencies] +mingling = "0.1.5" +``` + +> **Mingling** is an **async program**, so please use `async-std`, `tokio`, or another async runtime. + +2. This article assumes you are using the `tokio` async runtime. Add the following to your `Cargo.toml`: +```toml +tokio = { + version = "1", + features = [ + "macros", + "rt", + "rt-multi-thread" + ] +} +``` + +3. Write the basic code in your `main.rs` or other program entry point. +```rust +use mingling::macros::{dispatcher, gen_program, r_println, renderer}; + +#[tokio::main] +async fn main() { + // Create ThisProgram + let mut program = ThisProgram::new(); + + // Import the dispatcher `HelloCommand` + program.with_dispatcher(HelloCommand); + + // Run the program + program.exec().await; +} + +// Define the dispatcher `HelloCommand`, which routes the "hello" subcommand to `HelloEntry` +dispatcher!("hello", HelloCommand => HelloEntry); + +// Define the renderer, which receives `HelloEntry` and renders the content +#[renderer] +fn render_hello(_prev: HelloEntry) { + r_println!("Hello, World!") +} + +// Create ThisProgram at the end of the code +gen_program!(); +``` + +4. Install your command-line program and run it. +```bash +cargo install --path ./ +your_bin hello +``` +Result: +```bash +Hello, World! +``` + +## 💡 Next Steps +> **Mingling**'s basic components [Go](./pages/2-basic) |
