Skip to content

Commit

Permalink
fix(derive)!: Compile-error on nested subcommands
Browse files Browse the repository at this point in the history
Before, partial command lines would panic at runtime.  Now it'll be a
compile error

For example:
```
pub enum Opt {
  Daemon(DaemonCommand),
}

pub enum DaemonCommand {
  Start,
  Stop,
}
```

Gives:
```
error[E0277]: the trait bound `DaemonCommand: clap::Args` is not satisfied
   --> clap_derive/tests/subcommands.rs:297:16
    |
297 |         Daemon(DaemonCommand),
    |                ^^^^^^^^^^^^^ the trait `clap::Args` is not implemented for `DaemonCommand`
    |
    = note: required by `augment_args`
```

To nest this, you currently need `enum -> struct -> enum`.  A later
change will make it so you can use the `subcommand` attribute within
enums to cover this case.

This is a part of #2005
  • Loading branch information
epage committed Jul 14, 2021
1 parent 894be67 commit 7b594f1
Show file tree
Hide file tree
Showing 12 changed files with 827 additions and 749 deletions.
7 changes: 0 additions & 7 deletions clap_derive/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,6 @@ pub struct Attrs {
kind: Sp<Kind>,
}

/// Output for the gen_xxx() methods were we need more than a simple stream of tokens.
///
/// The output of a generation method is not only the stream of new tokens but also the attribute
/// information of the current element. These attribute information may contain valuable information
/// for any kind of child arguments.
pub type GenOutput = (TokenStream, Attrs);

impl Method {
pub fn new(name: Ident, args: TokenStream) -> Self {
Method { name, args }
Expand Down
Loading

0 comments on commit 7b594f1

Please sign in to comment.