use argh::FromArgs;
#[derive(FromArgs, PartialEq, Debug)]
struct TopLevel {
#[argh(subcommand)]
nested: MySubCommandEnum,
}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand)]
enum MySubCommandEnum {
One(SubCommandOne),
Two(SubCommandTwo),
}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "one", short = 'o')]
struct SubCommandOne {
#[argh(switch)]
fooey: bool,
}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "two")]
struct SubCommandTwo {
#[argh(switch)]
bar: bool,
}
#[test]
fn test_short_alias_dispatch() {
let expected = TopLevel { nested: MySubCommandEnum::One(SubCommandOne { fooey: true }) };
let actual = TopLevel::from_args(&["cmd"], &["one", "--fooey"]).expect("failed parsing 'one'");
assert_eq!(actual, expected);
let actual_short =
TopLevel::from_args(&["cmd"], &["o", "--fooey"]).expect("failed parsing 'o'");
assert_eq!(actual_short, expected);
}
#[test]
fn test_short_alias_redaction() {
let args = vec!["o", "--fooey"];
let redacted = TopLevel::redact_arg_values(&["cmd"], &args).expect("redaction failed");
assert!(!redacted.is_empty());
}
#[test]
fn test_no_short_alias_for_two() {
let res = TopLevel::from_args(&["cmd"], &["t", "--bar"]);
assert!(res.is_err());
}