Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. use structopt::StructOpt;
  2.  
  3. #[derive(Debug, StructOpt)]
  4. pub enum Command {
  5. #[structopt(name = "foo")]
  6. Foo {
  7. #[structopt(short = "i", long = "init")]
  8. init: bool,
  9.  
  10. #[structopt(short = "r", long = "remove")]
  11. remove: bool,
  12. },
  13.  
  14. #[structopt(name = "bar")]
  15. Bar {},
  16.  
  17. #[structopt(name = "baz")]
  18. Baz {},
  19. }
  20.  
  21. #[derive(Debug, StructOpt)]
  22. #[structopt()]
  23. pub struct Opts {
  24. /// Prints debug information
  25. #[structopt(short = "d", long = "debug")]
  26. pub debug: bool,
  27.  
  28. /// Specify configuration file
  29. #[structopt(short = "c", long = "config")]
  30. pub config: Option<String>,
  31.  
  32. #[structopt(subcommand)]
  33. pub cmd: Command,
  34. }
  35.  
  36. fn main() {
  37. let cmd = cli::Command::from_args();
  38.  
  39. match cmd.cmd {
  40. Foo { init, .. } => {
  41. do stuff with init
  42. },
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement