use clap::Parser;
use clap_fmt::FmtArgs;
use serde::Serialize;
#[derive(Parser, Debug, Serialize)]
struct CliWithRequired {
#[arg(short, long)]
required_str: String,
#[arg(short, long)]
optional_str: Option<String>,
#[arg(short, long, default_value = "default")]
with_default: String,
#[arg(long, required = true)]
must_have: String,
}
#[test]
fn test_required_fields() {
let cli = CliWithRequired {
required_str: "value".to_string(),
optional_str: None,
with_default: "custom".to_string(),
must_have: "present".to_string(),
};
let result = cli.to_args();
assert_eq!(result, vec!["--required-str", "value", "--with-default", "custom", "--must-have", "present"]);
}
#[test]
fn test_default_values_not_included() {
let cli = CliWithRequired {
required_str: "value".to_string(),
optional_str: None,
with_default: "default".to_string(), must_have: "present".to_string(),
};
let result = cli.to_args();
assert_eq!(result, vec!["--required-str", "value", "--must-have", "present"]);
}
#[test]
fn test_optional_with_value() {
let cli = CliWithRequired {
required_str: "req".to_string(),
optional_str: Some("opt".to_string()),
with_default: "default".to_string(),
must_have: "must".to_string(),
};
let result = cli.to_args();
assert_eq!(result, vec!["--required-str", "req", "--optional-str", "opt", "--must-have", "must"]);
}