google / google/argh

Allow subcommand flattening

Open
#126 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
Rust
Stars
2k
Forks
102
PR merge metrics
No merged PRs in 30d

Description

There is already an issue open for struct flattening. This one is specifically for subcommand flattenin.
Here is use-case example (using proc-macro from second comment):

```rust
#[derive(FromArgs, PartialEq, Debug)]
/// Top-level command.
struct TopLevel {
#[argh(subcommand)]
nested: MySubCommandEnum,
}

#[derive(PartialEq, Debug, FlattenSubcommand)]
enum MySubCommandEnum {
Global(MySubCommandEnumGlobal),
Sys(MySubCommandEnumSys),
}

#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand)]
enum MySubCommandEnumGlobal {
One(SubCommandOne),
Two(SubCommandTwo),
}

#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand)]
enum MySubCommandEnumSys {
Three(SubCommandThree),
Four(SubCommandFour),
}

#[derive(FromArgs, PartialEq, Debug)]
/// First subcommand.
#[argh(subcommand, name = "one")]
struct SubCommandOne {}

#[derive(FromArgs, PartialEq, Debug)]
/// Second subcommand.
#[argh(subcommand, name = "two")]
struct SubCommandTwo {
#[argh(option)]
/// x
x: usize,
}

#[derive(FromArgs, PartialEq, Debug)]
/// Third subcommand.
#[argh(subcommand, name = "three")]
struct SubCommandThree {}

#[derive(FromArgs, PartialEq, Debug)]
/// Fourth subcommand.
#[argh(subcommand, name = "four")]
struct SubCommandFour {}

fn main() {
let up: TopLevel = argh::from_env();
println!("{:?}", up);
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.