//! Example The Basic Usage of Mingling //! //! Run: //! ```base //! cargo run --manifest-path examples/example-basic/Cargo.toml --quiet -- greet //! cargo run --manifest-path examples/example-basic/Cargo.toml --quiet -- greet Alice //! ``` //! //! Output: //! ```plaintext //! Hello, World! //! Hello, Alice! //! ``` // Import commonly used Mingling modules use mingling::prelude::*; // Define the `greet` subcommand // _____________________________ subcmd name, can be nested (e.g. "remote.add" "remote.rm") // / _____________________ dispatcher name // | / _________ entry, records raw arguments // | | / ^^^^^^^^^^^^^ // vvvvv vvvvvvvv vvvvvvvvvv \_ equivalent to pack!(EntryGreet = Vec) dispatcher!("greet", CMDGreet => EntryGreet); fn main() { // Create a new ThisProgram let mut program = ThisProgram::new(); // Add the CMDGreet dispatcher program.with_dispatcher(CMDGreet); // Run the program, then exit the process program.exec_and_exit(); } // Quickly wrap a type into a type recognizable by the current program // ____________________ Wrapped type name // / _______ Wrapped type inner value // | / // vvvvvvvvvv vvvvvv pack!(ResultName = String); // Define the `handle_greet` chain for parsing input text // ____________________ Previous type: // / Mingling deduces types at runtime and routes them to this function // | _____ will be expanded to: // | / impl Into> #[chain] // vvvvvvvvvv vvvv fn handle_greet(args: EntryGreet) -> Next { let name: ResultName = args .inner .first() .cloned() .unwrap_or_else(|| "World".to_string()) .into(); name } // Define renderer `render_name`, used to render `ResultName` #[renderer] fn render_name(name: ResultName) { r_println!("Hello, {}!", *name); } // Note: This macro generates the program entry point. // It must be placed at the end of the root module of the crate (>= mingling@0.1.8). // ^^^^^^ ^^^^^^^^^^^ // For example: lib.rs, main.rs gen_program!();