clap_fmt 0.1.1

Serialize a clap arg parser into the command-line arguments.
Documentation
use clap::Parser;
use clap_fmt::FmtArgs;
use serde::Serialize;

// Test groups
#[derive(Parser, Debug, Serialize)]
#[command(group(
        clap::ArgGroup::new("vers")
            .required(false)
            .args(&["set_ver", "major", "minor", "patch"])
    ))]
struct CliWithGroups {
    #[arg(long, group = "vers")]
    set_ver: Option<String>,

    #[arg(long, group = "vers")]
    major: bool,

    #[arg(long, group = "vers")]
    minor: bool,

    #[arg(long, group = "vers")]
    patch: bool,
}

#[test]
fn test_groups_with_value() {
    let cli = CliWithGroups {
        set_ver: Some("1.2.3".to_string()),
        major: false,
        minor: false,
        patch: false,
    };

    let result = cli.to_args();
    assert_eq!(result, vec!["--set-ver", "1.2.3"]);
}

#[test]
fn test_groups_with_flag() {
    let cli = CliWithGroups {
        set_ver: None,
        major: true,
        minor: false,
        patch: false,
    };

    let result = cli.to_args();
    assert_eq!(result, vec!["--major"]);
}

#[test]
fn test_groups_none_selected() {
    let cli = CliWithGroups {
        set_ver: None,
        major: false,
        minor: false,
        patch: false,
    };

    let result = cli.to_args();
    assert_eq!(result, Vec::<String>::new());
}