//! Builder-chain argument example.
//!
//! Slash commands can carry structured arguments via a dotted builder chain:
//!
//! ```text
//! /build.target(release).jobs(4).lto
//! ```
//!
//! Each segment is either a bare flag (`lto`) or a key-value pair (`target(release)`).
//!
//! Run with: `cargo run --example parse_builder`

use slash_lang::parser::parse;

fn main() {
    let inputs = [
        // Single flag (no value)
        "/build.release",
        // Single key-value pair
        "/build.target(wasm32)",
        // Multiple key-value pairs
        "/build.target(release).jobs(4).lto",
        // Values containing dots are fine
        "/cargo.version(1.0.0)",
        // Empty value is treated as None
        "/run.dry-run()",
        // Chained with urgency and pipe
        "/Build.target(release)! | /test",
    ];

    for input in &inputs {
        println!("Input: {input}");
        match parse(input) {
            Ok(program) => {
                let cmd = &program.pipelines[0].commands[0];
                println!("  name: {}", cmd.name);
                if cmd.args.is_empty() {
                    println!("  args: (none)");
                } else {
                    for arg in &cmd.args {
                        match &arg.value {
                            Some(v) => println!("  arg:  {}={}", arg.name, v),
                            None => println!("  arg:  {} (flag)", arg.name),
                        }
                    }
                }
            }
            Err(e) => println!("  ERROR: {:?}", e),
        }
        println!();
    }
}
