mirror of
https://github.com/clap-rs/clap
synced 2025-01-05 17:28:42 +00:00
2821: test(derive): Port structopt flatten coverage r=epage a=epage 2822: feat(derive): Add support for lower/upper in rename_all r=epage a=epage Co-authored-by: Ed Page <eopage@gmail.com>
This commit is contained in:
commit
6c2daef7a1
3 changed files with 56 additions and 10 deletions
|
@ -80,6 +80,10 @@ pub enum CasingStyle {
|
||||||
ScreamingSnake,
|
ScreamingSnake,
|
||||||
/// Keep all letters lowercase and indicate word boundaries with underscores.
|
/// Keep all letters lowercase and indicate word boundaries with underscores.
|
||||||
Snake,
|
Snake,
|
||||||
|
/// Keep all letters lowercase and remove word boundaries.
|
||||||
|
Lower,
|
||||||
|
/// Keep all letters uppercase and remove word boundaries.
|
||||||
|
Upper,
|
||||||
/// Use the original attribute name defined in the code.
|
/// Use the original attribute name defined in the code.
|
||||||
Verbatim,
|
Verbatim,
|
||||||
}
|
}
|
||||||
|
@ -206,6 +210,8 @@ impl CasingStyle {
|
||||||
"pascal" | "pascalcase" => cs(Pascal),
|
"pascal" | "pascalcase" => cs(Pascal),
|
||||||
"screamingsnake" | "screamingsnakecase" => cs(ScreamingSnake),
|
"screamingsnake" | "screamingsnakecase" => cs(ScreamingSnake),
|
||||||
"snake" | "snakecase" => cs(Snake),
|
"snake" | "snakecase" => cs(Snake),
|
||||||
|
"lower" | "lowercase" => cs(Lower),
|
||||||
|
"upper" | "uppercase" => cs(Upper),
|
||||||
"verbatim" | "verbatimcase" => cs(Verbatim),
|
"verbatim" | "verbatimcase" => cs(Verbatim),
|
||||||
s => abort!(name, "unsupported casing: `{}`", s),
|
s => abort!(name, "unsupported casing: `{}`", s),
|
||||||
}
|
}
|
||||||
|
@ -226,6 +232,8 @@ impl Name {
|
||||||
Camel => s.to_mixed_case(),
|
Camel => s.to_mixed_case(),
|
||||||
ScreamingSnake => s.to_shouty_snake_case(),
|
ScreamingSnake => s.to_shouty_snake_case(),
|
||||||
Snake => s.to_snake_case(),
|
Snake => s.to_snake_case(),
|
||||||
|
Lower => s.to_snake_case().replace("_", ""),
|
||||||
|
Upper => s.to_shouty_snake_case().replace("_", ""),
|
||||||
Verbatim => s,
|
Verbatim => s,
|
||||||
};
|
};
|
||||||
quote_spanned!(ident.span()=> #s)
|
quote_spanned!(ident.span()=> #s)
|
||||||
|
@ -246,6 +254,8 @@ impl Name {
|
||||||
Camel => s.to_mixed_case(),
|
Camel => s.to_mixed_case(),
|
||||||
ScreamingSnake => s.to_shouty_snake_case(),
|
ScreamingSnake => s.to_shouty_snake_case(),
|
||||||
Snake => s.to_snake_case(),
|
Snake => s.to_snake_case(),
|
||||||
|
Lower => s.to_snake_case(),
|
||||||
|
Upper => s.to_shouty_snake_case(),
|
||||||
Verbatim => s,
|
Verbatim => s,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -288,3 +288,31 @@ fn test_rename_all_is_propagation_can_be_overridden() {
|
||||||
Opt::parse_from(&["test", "SECOND_VARIANT", "--foo-option"])
|
Opt::parse_from(&["test", "SECOND_VARIANT", "--foo-option"])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_lower_is_renamed() {
|
||||||
|
#[derive(Clap, Debug, PartialEq)]
|
||||||
|
struct Opt {
|
||||||
|
#[clap(rename_all = "lower", long)]
|
||||||
|
foo_option: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
Opt { foo_option: true },
|
||||||
|
Opt::parse_from(&["test", "--foooption"])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_upper_is_renamed() {
|
||||||
|
#[derive(Clap, Debug, PartialEq)]
|
||||||
|
struct Opt {
|
||||||
|
#[clap(rename_all = "upper", long)]
|
||||||
|
foo_option: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
Opt { foo_option: true },
|
||||||
|
Opt::parse_from(&["test", "--FOOOPTION"])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -155,21 +155,29 @@ fn update_subcommands_with_flatten() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn flatten_with_doc_comment() {
|
fn flatten_with_doc_comment() {
|
||||||
#[derive(Clap, Debug)]
|
#[derive(Clap, PartialEq, Debug)]
|
||||||
struct DaemonOpts {
|
struct Common {
|
||||||
#[clap(short)]
|
/// This is an arg. Arg means "argument". Command line argument.
|
||||||
user: String,
|
arg: i32,
|
||||||
#[clap(short)]
|
|
||||||
group: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clap, Debug)]
|
#[derive(Clap, PartialEq, Debug)]
|
||||||
#[clap(name = "basic")]
|
|
||||||
struct Opt {
|
struct Opt {
|
||||||
/// A very important doc comment I just can't leave out!
|
/// The very important comment that clippy had me put here.
|
||||||
|
/// It knows better.
|
||||||
#[clap(flatten)]
|
#[clap(flatten)]
|
||||||
opts: DaemonOpts,
|
common: Common,
|
||||||
}
|
}
|
||||||
|
assert_eq!(
|
||||||
|
Opt {
|
||||||
|
common: Common { arg: 42 }
|
||||||
|
},
|
||||||
|
Opt::parse_from(&["test", "42"])
|
||||||
|
);
|
||||||
|
|
||||||
|
let help = utils::get_help::<Opt>();
|
||||||
|
assert!(help.contains("This is an arg."));
|
||||||
|
assert!(!help.contains("The very important"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue