Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derive doc clap ordering for multiple Clap #2531

Merged
merged 1 commit into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clap_derive/src/derives/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}}
Expand Down
44 changes: 44 additions & 0 deletions clap_derive/tests/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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::<Command>();

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::<Command>();

assert!(short_help.contains("This is the docstring for Flattened"));
}