From 0a2ef958c0dca21d19e4ffc38ba5a7c4078e182a Mon Sep 17 00:00:00 2001 From: Weicao-CatilGrass <1992414357@qq.com> Date: Sat, 23 May 2026 23:41:04 +0800 Subject: Rework examples and add entry macro for testing --- examples/example-help/Cargo.lock | 76 +++++++++++++++++++++++++++++++++++++++ examples/example-help/Cargo.toml | 7 ++++ examples/example-help/src/main.rs | 41 +++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 examples/example-help/Cargo.lock create mode 100644 examples/example-help/Cargo.toml create mode 100644 examples/example-help/src/main.rs (limited to 'examples/example-help') diff --git a/examples/example-help/Cargo.lock b/examples/example-help/Cargo.lock new file mode 100644 index 0000000..5e16d19 --- /dev/null +++ b/examples/example-help/Cargo.lock @@ -0,0 +1,76 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "example-help" +version = "0.1.0" +dependencies = [ + "mingling", +] + +[[package]] +name = "just_fmt" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5454cda0d57db59778608d7a47bff5b16c6705598265869fb052b657f66cf05e" + +[[package]] +name = "mingling" +version = "0.1.9" +dependencies = [ + "mingling_core", + "mingling_macros", +] + +[[package]] +name = "mingling_core" +version = "0.1.9" +dependencies = [ + "just_fmt", +] + +[[package]] +name = "mingling_macros" +version = "0.1.9" +dependencies = [ + "just_fmt", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" diff --git a/examples/example-help/Cargo.toml b/examples/example-help/Cargo.toml new file mode 100644 index 0000000..01e6801 --- /dev/null +++ b/examples/example-help/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "example-help" +version = "0.1.0" +edition = "2024" + +[dependencies] +mingling = { path = "../../mingling" } diff --git a/examples/example-help/src/main.rs b/examples/example-help/src/main.rs new file mode 100644 index 0000000..9567c49 --- /dev/null +++ b/examples/example-help/src/main.rs @@ -0,0 +1,41 @@ +//! Example Help +//! +//! > This example demonstrates how to use the `#[help]` macro to generate help information, +//! > enabling `--help` to work +//! +//! Run +//! ```bash +//! cargo run --manifest-path examples/example-help/Cargo.toml --quiet -- greet --help +//! ``` +//! +//! Output: +//! ```plain +//! Usage: greet +//! ``` + +use mingling::{macros::help, prelude::*, setup::BasicProgramSetup}; + +dispatcher!("greet", CMDGreet => EntryGreet); + +// Define help _________ When `program.user_context.help` is `true` +// / the command will not enter `#[chain]` / `#[renderer]` +#[help] // vvvvvvvvvv but instead enter this `#[help]` function +fn help_greet(_prev: EntryGreet) { + r_println!("Usage: greet "); +} + +fn main() { + let mut program = ThisProgram::new(); + + // --------- IMPORTANT --------- + // Add `BasicProgramSetup` to the program + // to enable `--help`, `--quiet`, and other built-in features + program.with_setup(BasicProgramSetup); + // --------- IMPORTANT --------- + + program.with_dispatcher(CMDGreet); + + program.exec_and_exit(); +} + +gen_program!(); -- cgit