simple_macro_test/
simple_macro_test.rs1use cli_command::{cli_args, parse_command_line};
7
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9 println!("🔧 Simple CLI Args Macro Demo");
10 println!();
11
12 let (name, age, email, port) = cli_args!(
13 name: String = "Anonymous".to_string(),
14 age: u32 = 25,
15 email: String = "user@example.com".to_string(),
16 port: u16 = 8080
17 );
18
19 let cmd = parse_command_line()?;
20 let is_active = cmd.contains_argument("is-active");
21
22 println!("📋 Parsed Arguments:");
23 println!(" Name: {}", name);
24 println!(" Age: {}", age);
25 println!(" Email: {}", email);
26 println!(" Active: {}", is_active);
27 println!(" Port: {}", port);
28
29 println!();
30 println!("✨ Notice how the cli_args! macro eliminated this boilerplate:");
31 println!(" let name = cmd.get_argument_or_default(\"name\", \"Anonymous\".to_string())?;");
32 println!(" let age = cmd.get_argument_or_default(\"age\", 25)?;");
33 println!(
34 " let email = cmd.get_argument_or_default(\"email\", \"user@example.com\".to_string())?;"
35 );
36 println!(" let is_active = cmd.get_argument_or_default(\"is_active\", true)?;");
37 println!(" let port = cmd.get_argument_or_default(\"port\", 8080)?;");
38
39 println!();
40 println!("🚀 Try running with different arguments:");
41 println!(" cargo run --example simple_macro_test -- --name Alice --age 30 --port 3000");
42 println!(" cargo run --example simple_macro_test -- --name Bob --email bob@company.com --is-active false");
43
44 Ok(())
45}