1  // Copyright (c) 2022 Google LLC All rights reserved.
2  // Use of this source code is governed by a BSD-style
3  // license that can be found in the LICENSE file.
4  
5  use {argh::FromArgs, std::fmt::Debug};
6  
7  #[derive(FromArgs, PartialEq, Debug)]
8  /// Top-level command.
9  struct TopLevel {
10      #[argh(subcommand)]
11      nested: MySubCommandEnum,
12  }
13  
14  #[derive(FromArgs, PartialEq, Debug)]
15  #[argh(subcommand)]
16  enum MySubCommandEnum {
17      One(SubCommandOne),
18      Two(SubCommandTwo),
19  }
20  
21  #[derive(FromArgs, PartialEq, Debug)]
22  /// First subcommand.
23  #[argh(subcommand, name = "one")]
24  struct SubCommandOne {
25      #[argh(option)]
26      /// how many x
27      x: usize,
28  }
29  
30  #[derive(FromArgs, PartialEq, Debug)]
31  /// Second subcommand.
32  #[argh(subcommand, name = "two")]
33  struct SubCommandTwo {
34      #[argh(switch)]
35      /// whether to fooey
36      fooey: bool,
37  }
38  
main()39  fn main() {
40      let toplevel: TopLevel = argh::from_env();
41      println!("{:#?}", toplevel);
42  }
43