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

flatten is not an Arg attribute in derive API #4505

Closed
2 tasks done
emersonford opened this issue Nov 23, 2022 · 1 comment
Closed
2 tasks done

flatten is not an Arg attribute in derive API #4505

emersonford opened this issue Nov 23, 2022 · 1 comment
Labels
C-bug Category: Updating dependencies

Comments

@emersonford
Copy link
Contributor

emersonford commented Nov 23, 2022

Please complete the following tasks

Rust Version

1.65.0

Clap Version

4.0.26

Minimal reproducible code

use clap::Args;

#[derive(Args)]
struct CommonArgs {
    #[arg(long)]
    pub foo: u32
}

#[derive(Args)]
struct SomeArgs {
    pub bar: u32,
    
    #[arg(flatten)]
    pub common: CommonArgs,
}

Steps to reproduce the bug with the above code

build; playground link

Actual Behaviour

fails to compile with

error: Expected `command` attribute instead of `arg`
  --> src/lib.rs:13:7
   |
13 |     #[arg(flatten)]
   |       ^^^

error: could not compile `playground` due to previous error

Expected Behaviour

should compile, the derive reference (see here) says that flatten is a valid Arg attribute.

Additional Context

workaround is to use #[command(flatten)] or #[clap(flatten)] instead of #[arg(flatten)]. the former feels... incorrect? and iirc the latter is no longer recommended in favor of #[arg(...)].

Debug Output

No response

@emersonford emersonford added the C-bug Category: Updating dependencies label Nov 23, 2022
@epage epage closed this as completed in bf39b8d Nov 28, 2022
@epage
Copy link
Member

epage commented Nov 28, 2022

Thanks for catching this! The documentation is updated in master.

#[command(flatten)] is the correct route to go as you are merging together information about the command, rather than setting attributes related to a specific Arg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Updating dependencies
Projects
None yet
Development

No branches or pull requests

2 participants