From f484e2da11dfc83cdd15557b6e8f4f5167a078ab Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Thu, 10 Jun 2021 21:56:38 +0800 Subject: [PATCH] Derive doc clap ordering for multiple Clap Fix #2527 --- clap_derive/src/derives/args.rs | 2 +- clap_derive/tests/flatten.rs | 44 +++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/clap_derive/src/derives/args.rs b/clap_derive/src/derives/args.rs index ce32b867..6361bced 100644 --- a/clap_derive/src/derives/args.rs +++ b/clap_derive/src/derives/args.rs @@ -340,8 +340,8 @@ pub fn gen_augment( let app_methods = parent_attribute.top_level_methods(); let version = parent_attribute.version(); quote! {{ - let #app_var = #app_var#app_methods; #( #args )* + let #app_var = #app_var#app_methods; #subcmd #app_var#version }} diff --git a/clap_derive/tests/flatten.rs b/clap_derive/tests/flatten.rs index febca659..f3af9656 100644 --- a/clap_derive/tests/flatten.rs +++ b/clap_derive/tests/flatten.rs @@ -12,7 +12,10 @@ // commit#ea76fa1b1b273e65e3b0b1046643715b49bec51f which is licensed under the // MIT/Apache 2.0 license. +mod utils; + use clap::Clap; +use utils::get_help; #[test] fn flatten() { @@ -168,3 +171,44 @@ fn flatten_with_doc_comment() { opts: DaemonOpts, } } + +#[test] +fn docstrings_ordering_with_multiple_clap() { + /// This is the docstring for Flattened + #[derive(Clap)] + struct Flattened { + #[clap(long)] + foo: bool, + } + + /// This is the docstring for Command + #[derive(Clap)] + struct Command { + #[clap(flatten)] + flattened: Flattened, + } + + let short_help = get_help::(); + + assert!(short_help.contains("This is the docstring for Command")); +} + +#[test] +fn docstrings_ordering_with_multiple_clap_partial() { + /// This is the docstring for Flattened + #[derive(Clap)] + struct Flattened { + #[clap(long)] + foo: bool, + } + + #[derive(Clap)] + struct Command { + #[clap(flatten)] + flattened: Flattened, + } + + let short_help = get_help::(); + + assert!(short_help.contains("This is the docstring for Flattened")); +}